Skip to content

Commit

Permalink
v1.2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
soonjokwon committed Jul 27, 2022
1 parent 618be25 commit 22924c2
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 64 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ The NIST [STEP to X3D Translator](https://www.nist.gov/services-resources/softwa
- NIST STP2X3D is a command line software. Please check out the [Usage guide](USAGE.md).

## Work In Progress
- Setting of adaptive tessellation parameters per each body.
- Translation of geometries (faces, edges) linked to GD&T items.
- Determination of an appropriate tessellation parameters per each body.

## Contact Information
- Soonjo Kwon, [email protected]
Expand All @@ -49,7 +48,7 @@ The NIST [STEP to X3D Translator](https://www.nist.gov/services-resources/softwa
- R. R. Lipman, S. Kwon, 2021, [**STEP File Analyzer and Viewer User Guide (Update 7)**](https://nvlpubs.nist.gov/nistpubs/ams/NIST.AMS.200-12.pdf), *NIST Advanced Manufacturing Series*, 200-12.

## Version
1.10
1.20

## Disclaimers
[NIST Disclaimer](https://www.nist.gov/disclaimer)
14 changes: 13 additions & 1 deletion STP2X3D/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Component::Component(const TopoDS_Shape& shape)
: m_parentComponent(nullptr),
m_originalComponent(nullptr),
m_hasUniqueName(false),
m_shape(shape)
m_shape(shape),
m_stepID(-1)
{
}

Expand Down Expand Up @@ -195,6 +196,17 @@ bool Component::IsEmpty(void) const
return false;
}

bool Component::HasHiddenShape(void) const
{
for (const auto& iShape : m_iShapes)
{
if (iShape->IsHidden())
return true;
}

return false;
}

const Bnd_Box Component::GetBoundingBox(bool sketch) const
{
Bnd_Box bndBox;
Expand Down
7 changes: 7 additions & 0 deletions STP2X3D/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Component
void SetTransformation(const gp_Trsf& trsf) { m_trsf = trsf; }
void SetParentComponent(Component* parentComp) { m_parentComponent = parentComp; }
void SetOriginalComponent(Component*& originalComp);
void SetShape(const TopoDS_Shape& shape) { m_shape = shape; }

void AddSubComponent(Component*& subComp);
void AddIShape(IShape*& iShape);
Expand All @@ -37,9 +38,14 @@ class Component
bool IsAssembly(void) const;
bool IsRoot(void) const;
bool IsEmpty(void) const;
bool HasHiddenShape(void) const;

void Clean(void);

// SFA-specific
void SetStepID(int stepID) { m_stepID = stepID; }
const int GetStepID(void) const { return m_stepID; }

protected:
void AddCopiedComponent(Component* copiedComp) { m_copiedComponents.push_back(copiedComp); }
Component* GetCopiedComponentAt(int index) const { return m_copiedComponents[index]; }
Expand All @@ -61,6 +67,7 @@ class Component
TopoDS_Shape m_shape;
gp_Trsf m_trsf;
bool m_hasUniqueName;
int m_stepID;

Component* m_originalComponent;
Component* m_parentComponent;
Expand Down
4 changes: 3 additions & 1 deletion STP2X3D/IShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ IShape::IShape(const TopoDS_Shape& shape)
m_isMultiTransparent(false),
m_isTransparent(false),
m_isFaceSet(false),
m_isHidden(false),
m_component(nullptr),
m_globalIndex(0)
m_globalIndex(0),
m_stepID(-1)
{
// Check if the shape is a face set
if (OCCUtil::HasFace(m_shape))
Expand Down
9 changes: 9 additions & 0 deletions STP2X3D/IShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class IShape
void SetComponent(Component* comp) { m_component = comp; }
void SetGlobalIndex(int globalIndex) { m_globalIndex = globalIndex; }
void SetTessellated(bool isTessellated) { m_isTessellated = isTessellated; }
void SetHidden(bool isHidden) { m_isHidden = isHidden; }

void AddColor(const TopoDS_Shape& shape, const Quantity_ColorRGBA& color);
void AddMesh(Mesh*& mesh) { m_meshList.push_back(mesh); }
Expand All @@ -37,11 +38,17 @@ class IShape
bool IsFaceSet(void) const { return m_isFaceSet; }
bool IsSketchGeometry(void) const { return !m_isFaceSet; }

bool IsHidden(void) const { return m_isHidden; }

bool IsEmpty(void) const;

// SFA-specific
wstring GetUniqueName(void) const;

void SetStepID(int stepID) { m_stepID = stepID; }
const int GetStepID(void) const { return m_stepID; }


protected:
void CheckColor(const Quantity_ColorRGBA& color);
void Clear(void);
Expand All @@ -50,12 +57,14 @@ class IShape
wstring m_name;
TopoDS_Shape m_shape;
int m_globalIndex;
int m_stepID;

bool m_isMultiColored;
bool m_isMultiTransparent;
bool m_isTransparent;
bool m_isTessellated;
bool m_isFaceSet;
bool m_isHidden;

Component* m_component;

Expand Down
4 changes: 4 additions & 0 deletions STP2X3D/OCCUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ namespace OCCUtil
double GetDeflection(const TopoDS_Shape& shape)
{
Bnd_Box bndBox = ComputeBoundingBox(shape);

bndBox = bndBox.FinitePart();

gp_Pnt minPnt = bndBox.CornerMin();
gp_Pnt maxPnt = bndBox.CornerMax();

double deviationCoefficient = 0.001;

double deflection = Prs3d::GetDeflection(Graphic3d_Vec3d(minPnt.X(), minPnt.Y(), minPnt.Z()), Graphic3d_Vec3d(maxPnt.X(), maxPnt.Y(), maxPnt.Z()), deviationCoefficient);
Expand Down
3 changes: 2 additions & 1 deletion STP2X3D/S2X_Option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ S2X_Option::S2X_Option()
m_quality(5.0),
m_batch(-1),
m_SFA(true),
m_gdt(false)
m_gdt(false),
m_rosette(false)
{
}

Expand Down
7 changes: 5 additions & 2 deletions STP2X3D/S2X_Option.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class S2X_Option
void SetBatch(const int& batch) { m_batch = batch; }
void SetSFA(bool sfa) { m_SFA = sfa; }
void SetGDT(bool gdt) { m_gdt = gdt; }
void SetRosette(bool rosette) { m_rosette = rosette; }

const wstring& Input(void) const { return m_input; }
const wstring Output(void) const;
Expand All @@ -30,9 +31,10 @@ class S2X_Option
int Batch(void) const { return m_batch; }
bool SFA(void) const { return m_SFA; }
bool GDT(void) const { return m_gdt; }
bool Rosette(void) const { return m_rosette; }

// Software version (as of Jan 2021)
const wstring Version(void) const { return L"1.10"; }
// Software version (as of Feb 2022)
const wstring Version(void) const { return L"1.20"; }

private:
wstring m_input; // Input file path
Expand All @@ -46,4 +48,5 @@ class S2X_Option
int m_batch; // Batch option
bool m_SFA; // Specific to SFA
bool m_gdt; // GD&T option
bool m_rosette; // Rosette used in Composite Design
};
99 changes: 95 additions & 4 deletions STP2X3D/STEP_Data.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include "stdafx.h"
#include "STEP_Data.h"

#include <StepData_UndefinedEntity.hxx>
#include <Interface_UndefinedContent.hxx>
#include <Interface_EntityList.hxx>
#include <StepGeom_CompositeCurve.hxx>
#include <StepGeom_CompositeCurveSegment.hxx>
#include <StepGeom_HArray1OfCompositeCurveSegment.hxx>
#include <StepToTopoDS_TranslateCompositeCurve.hxx>

STEP_Data::STEP_Data(const STEPControl_Reader& reader)
{
Expand All @@ -25,9 +31,10 @@ void STEP_Data::StoreStepDataForShapes(const STEPControl_Reader& reader)
for (int i = 1; i <= entitySize; ++i)
{
const Handle(Standard_Transient)& entity = model->Value(i);

Handle(StepRepr_RepresentationItem) repItem = Handle(StepRepr_RepresentationItem)::DownCast(entity);
StoreHiddenShape(entity, workSession, transProcess);

Handle(StepRepr_RepresentationItem) repItem = Handle(StepRepr_RepresentationItem)::DownCast(entity);

// Skip if entity is not of type representation_item
if (repItem.IsNull())
continue;
Expand Down Expand Up @@ -62,6 +69,90 @@ void STEP_Data::StoreStepDataForShapes(const STEPControl_Reader& reader)
}
}

void STEP_Data::StoreHiddenShape(const Handle(Standard_Transient)& entity, const Handle(XSControl_WorkSession)& workSession, const Handle(Transfer_TransientProcess)& transProcess)
{
string stepEntityType = entity->DynamicType()->Name();

if (stepEntityType == "StepData_UndefinedEntity")
{
Handle(StepData_UndefinedEntity) undefEnt = Handle(StepData_UndefinedEntity)::DownCast(entity);

if (undefEnt->IsComplex())
{
bool isCURVE_11 = false; // Rosette used in Composite Design

while (undefEnt)
{
string type = undefEnt->StepType();

if (type == "CURVE_11")
{
isCURVE_11 = true;
break;
}

undefEnt = undefEnt->Next();
}

// Check CURVE_11
if (isCURVE_11)
undefEnt = Handle(StepData_UndefinedEntity)::DownCast(entity);
else
return;

// Generate a composite_curve
while (undefEnt)
{
string type = undefEnt->StepType();

if (type == "COMPOSITE_CURVE")
{
Handle(Interface_UndefinedContent) intUndefCont = undefEnt->UndefinedContent();
Interface_EntityList entList = intUndefCont->EntityList();
Handle(Standard_Transient) ent = entList.Value(1);

Handle(StepData_UndefinedEntity) undefEnt2 = Handle(StepData_UndefinedEntity)::DownCast(ent);
intUndefCont = undefEnt2->UndefinedContent();

entList = intUndefCont->EntityList();

int entCount = entList.NbEntities();
StepGeom_HArray1OfCompositeCurveSegment* compCurvSegArr = new StepGeom_HArray1OfCompositeCurveSegment(1, entCount);

for (int i = 1; i <= entCount; ++i)
{
Handle(Standard_Transient) ent = entList.Value(i);
Handle(StepGeom_CompositeCurveSegment) compCurvSeg = Handle(StepGeom_CompositeCurveSegment)::DownCast(ent);

compCurvSegArr->SetValue(i, compCurvSeg);
}

Handle(StepGeom_HArray1OfCompositeCurveSegment) h_compCurvSegArr = Handle(StepGeom_HArray1OfCompositeCurveSegment)(compCurvSegArr);

StepGeom_CompositeCurve* compCurv = new StepGeom_CompositeCurve();
compCurv->SetSegments(h_compCurvSegArr);
Handle(StepGeom_CompositeCurve) h_compCurv = Handle(StepGeom_CompositeCurve)(compCurv);

StepToTopoDS_TranslateCompositeCurve* compCurvTrans = new StepToTopoDS_TranslateCompositeCurve(h_compCurv, transProcess);
TopoDS_Shape shape = (TopoDS_Shape)compCurvTrans->Value();

m_hiddenShapes.push_back(shape);

int shapeID = OCCUtil::GetID(shape);

string id(workSession->EntityLabel(entity)->ToCString());
int stepEntityID = atoi(id.substr(1, id.length()).c_str());
m_shapeIDentityIDMap.insert({ shapeID,stepEntityID });

break;
}

undefEnt = undefEnt->Next();
}
}
}
}

const string STEP_Data::GetEntityTypeFromShape(const TopoDS_Shape& shape) const
{
int shapeID = OCCUtil::GetID(shape);
Expand All @@ -76,7 +167,7 @@ const string STEP_Data::GetEntityTypeFromShape(const TopoDS_Shape& shape) const
const int STEP_Data::GetEntityIDFromShape(const TopoDS_Shape& shape) const
{
int shapeID = OCCUtil::GetID(shape);
int stepEntityID = 0;
int stepEntityID = -1;

if (m_shapeIDentityIDMap.find(shapeID) != m_shapeIDentityIDMap.end())
stepEntityID = m_shapeIDentityIDMap.find(shapeID)->second;
Expand Down
6 changes: 6 additions & 0 deletions STP2X3D/STEP_Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ class STEP_Data

bool IsMappedItem(const TopoDS_Shape& shape) const;

TopoDS_Shape GetHiddenShapeAt(int index) { return m_hiddenShapes[index]; }
int GetHiddenShapeSize(void) { return (int)m_hiddenShapes.size(); }

protected:
void StoreStepDataForShapes(const STEPControl_Reader& reader);
void StoreHiddenShape(const Handle(Standard_Transient)& entity, const Handle(XSControl_WorkSession)& workSession, const Handle(Transfer_TransientProcess)& transProcess);
void Clear(void);

private:
unordered_map<int, string> m_shapeIDentityTypeMap;
unordered_map<int, int> m_shapeIDentityIDMap;

vector<TopoDS_Shape> m_hiddenShapes;
};
Loading

0 comments on commit 22924c2

Please sign in to comment.