Save occ identifications in step file

This commit is contained in:
mhochsteger@cerbsim.com 2021-11-04 21:58:56 +01:00
parent ef1bf2f727
commit 225312b9d9
3 changed files with 89 additions and 8 deletions

View File

@ -130,6 +130,9 @@ public:
// (*testout) << "Rotation - Transformation:" << (*this) << endl; // (*testout) << "Rotation - Transformation:" << (*this) << endl;
} }
Mat<D> & GetMatrix() { return m; }
Vec<D> & GetVector() { return v; }
/// ///
Transformation CalcInverse () const Transformation CalcInverse () const
{ {

View File

@ -2045,14 +2045,16 @@ namespace netgen
if(item.IsNull()) if(item.IsNull())
continue; continue;
auto shape_item = item->ItemElementValue(1);
TopoDS_Shape shape = TransferBRep::ShapeResult(transProc->Find(shape_item));
string name = item->Name()->ToCString(); string name = item->Name()->ToCString();
if(name == "netgen_geometry_identification")
ReadIdentifications(item, transProc);
if(name != "netgen_geometry_properties") if(name != "netgen_geometry_properties")
continue; continue;
auto shape_item = item->ItemElementValue(1);
Handle(Transfer_Binder) binder;
binder = transProc->Find(shape_item);
TopoDS_Shape shape = TransferBRep::ShapeResult(binder);
auto & prop = OCCGeometry::global_shape_properties[shape.TShape()]; auto & prop = OCCGeometry::global_shape_properties[shape.TShape()];
auto nprops = item->NbItemElement(); auto nprops = item->NbItemElement();
@ -2093,9 +2095,8 @@ namespace netgen
if(auto hpref = prop.hpref; hpref != default_props.hpref) if(auto hpref = prop.hpref; hpref != default_props.hpref)
props.Append( MakeReal(hpref, "hpref") ); props.Append( MakeReal(hpref, "hpref") );
if(props.Size()==1) if(props.Size()>1)
return; {
for(auto & item : props.Range(1, props.Size())) for(auto & item : props.Range(1, props.Size()))
model->AddEntity(item); model->AddEntity(item);
@ -2103,6 +2104,68 @@ namespace netgen
model->AddEntity(compound); model->AddEntity(compound);
} }
WriteIdentifications(model, shape, finder);
}
void WriteIdentifications(const Handle(Interface_InterfaceModel) model, const TopoDS_Shape & shape, const Handle(Transfer_FinderProcess) finder)
{
Handle(StepRepr_RepresentationItem) item = STEPConstruct::FindEntity(finder, shape);
auto & identifications = OCCGeometry::identifications[shape.TShape()];
if(identifications.size()==0)
return;
auto n = identifications.size();
Array<Handle(StepRepr_RepresentationItem)> ident_items;
ident_items.Append(item);
for(auto & ident : identifications)
{
Array<Handle(StepRepr_RepresentationItem)> items;
items.Append(STEPConstruct::FindEntity(finder, ident.other));
items.Append(MakeInt(static_cast<int>(ident.inverse)));
auto & m = ident.trafo.GetMatrix();
for(auto i : Range(9))
items.Append(MakeReal(m(i)));
auto & v = ident.trafo.GetVector();
for(auto i : Range(3))
items.Append(MakeReal(v(i)));
for(auto & item : items.Range(1,items.Size()))
model->AddEntity(item);
ident_items.Append(MakeCompound(items, ident.name));
}
for(auto & item : ident_items.Range(1,ident_items.Size()))
model->AddEntity(item);
auto comp = MakeCompound(ident_items, "netgen_geometry_identification");
model->AddEntity(comp);
}
void ReadIdentifications(Handle(StepRepr_RepresentationItem) item, Handle(Transfer_TransientProcess) transProc)
{
auto idents = Handle(StepRepr_CompoundRepresentationItem)::DownCast(item);
auto n = idents->NbItemElement();
std::vector<OCCIdentification> result;
auto shape_origin = TransferBRep::ShapeResult(transProc->Find(idents->ItemElementValue(1)));
for(auto i : Range(2,n+1))
{
auto id_item = Handle(StepRepr_CompoundRepresentationItem)::DownCast(idents->ItemElementValue(i));
OCCIdentification ident;
ident.name = id_item->Name()->ToCString();
ident.other = TransferBRep::ShapeResult(transProc->Find(id_item->ItemElementValue(1)));
ident.inverse = static_cast<bool>(ReadInt(id_item->ItemElementValue(2)));
auto & m = ident.trafo.GetMatrix();
for(auto i : Range(9))
m(i) = ReadReal(id_item->ItemElementValue(3+i));
auto & v = ident.trafo.GetVector();
for(auto i : Range(3))
v(i) = ReadReal(id_item->ItemElementValue(12+i));
result.push_back(ident);
}
OCCGeometry::identifications[shape_origin.TShape()] = result;
}
void WriteSTEP(const TopoDS_Shape & shape, string filename) void WriteSTEP(const TopoDS_Shape & shape, string filename)
{ {
Interface_Static::SetCVal("write.step.schema", "AP242IS"); Interface_Static::SetCVal("write.step.schema", "AP242IS");

View File

@ -520,6 +520,11 @@ namespace netgen
return int_obj; return int_obj;
} }
inline int ReadInt (Handle(StepRepr_RepresentationItem) item)
{
return Handle(StepRepr_IntegerRepresentationItem)::DownCast(item)->Value();
}
inline Handle(StepRepr_RepresentationItem) MakeReal (double val, string name = "") inline Handle(StepRepr_RepresentationItem) MakeReal (double val, string name = "")
{ {
Handle(StepBasic_MeasureValueMember) value_member = new StepBasic_MeasureValueMember; Handle(StepBasic_MeasureValueMember) value_member = new StepBasic_MeasureValueMember;
@ -529,6 +534,13 @@ namespace netgen
return value_repr; return value_repr;
} }
inline double ReadReal (Handle(StepRepr_RepresentationItem) item)
{
return Handle(StepRepr_ValueRepresentationItem)::DownCast(item)
->ValueComponentMember()->Real();
}
inline Handle(StepRepr_RepresentationItem) MakeCompound( FlatArray<Handle(StepRepr_RepresentationItem)> items, string name = "" ) inline Handle(StepRepr_RepresentationItem) MakeCompound( FlatArray<Handle(StepRepr_RepresentationItem)> items, string name = "" )
{ {
Handle(StepRepr_HArray1OfRepresentationItem) array_repr = new StepRepr_HArray1OfRepresentationItem(1,items.Size()); Handle(StepRepr_HArray1OfRepresentationItem) array_repr = new StepRepr_HArray1OfRepresentationItem(1,items.Size());
@ -541,6 +553,9 @@ namespace netgen
return comp; return comp;
} }
void WriteIdentifications(const Handle(Interface_InterfaceModel) model, const TopoDS_Shape & shape, const Handle(Transfer_FinderProcess) finder);
void ReadIdentifications(Handle(StepRepr_RepresentationItem) item, Handle(Transfer_TransientProcess) transProc);
inline Quantity_ColorRGBA MakeColor(const Vec<4> & c) inline Quantity_ColorRGBA MakeColor(const Vec<4> & c)
{ {
return Quantity_ColorRGBA (c[0], c[1], c[2], c[3]); return Quantity_ColorRGBA (c[0], c[1], c[2], c[3]);