38 #include <Interface_Static.hxx> 39 #include <BRepBuilderAPI_Transform.hxx> 40 #include <TDataStd_Name.hxx> 41 #include <XCAFDoc_DocumentTool.hxx> 42 #include <Standard.hxx> 44 #include <XCAFApp_Application.hxx> 60 Handle (XCAFApp_Application)
A = XCAFApp_Application::GetApplication();
62 A->NewDocument (
"MDTV-XCAF", fDoc);
65 ::Error(
"TOCCToStep::OCCDocCreation",
"creating OCC application");
73 TDF_Label motherLabel;
81 fLabel = XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NewShape();
83 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(fLabel, fShape);
85 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
88 while ((currentVolume = (
TGeoVolume *)next())) {
89 if (GetLabelOfVolume(currentVolume).IsNull()) {
91 if ((GetLabelOfVolume(currentVolume).IsNull())) {
95 fShape = fRootShape.OCC_SimpleShape(currentVolume->
GetShape());
100 while ((current = nextNode())) {
101 if ((current->
GetVolume() == currentVolume) && (GetLabelOfVolume(current->
GetVolume()).IsNull())) {
103 nextNode.GetPath(path);
107 TGeoNode * mother = nextNode.GetNode(--level);
110 motherLabel = GetLabelOfVolume(motherVol);
111 if (!motherLabel.IsNull()) {
112 fLabel = TDF_TagSource::NewChild(motherLabel);
115 TGeoNode * grandMother = nextNode.GetNode(level);
117 TopoDS_Shape Mothershape;
121 Mothershape = fRootShape.OCC_SimpleShape(motherVol->
GetShape());
123 motherLabel = TDF_TagSource::NewChild(GetLabelOfVolume(Top));
124 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(motherLabel, Mothershape);
125 TDataStd_Name::Set(motherLabel, motherVol->
GetName());
126 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
127 fTree[motherVol] = motherLabel;
128 fLabel = TDF_TagSource::NewChild(motherLabel);
133 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(fLabel, fShape);
134 TDataStd_Name::Set(fLabel, currentVolume->
GetName());
135 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
136 fTree[currentVolume] = fLabel;
146 STEPControl_StepModelType mode = STEPControl_AsIs;
147 fWriter.SetNameMode(Standard_True);
148 if (!Interface_Static::SetIVal(
"write.step.assembly", 1)) {
149 Error(
"TOCCToStep::OCCWriteStep",
"failed to set assembly mode for step data");
151 if (!fWriter.Transfer(fDoc, mode)) {
152 ::Error(
"TOCCToStep::OCCWriteStep",
"error translating document");
154 fWriter.Write(fname);
162 if (fTree.find(v) != fTree.end())
172 map <TGeoVolume *,TDF_Label>::iterator it;
173 for(it = fTree.begin(); it != fTree.end(); ++it)
174 if (it->second.IsEqual(fLabel))
183 XCAFDoc_DocumentTool::ShapeTool(mother)->AddComponent(mother, child,loc);
184 XCAFDoc_DocumentTool::ShapeTool(mother)->UpdateAssembly(mother);
192 TopLoc_Location locA;
195 TR1.SetTranslation(gp_Vec(t[0],t[1],t[2]));
196 TR.SetValues(r[0],r[1],r[2],0,
199 #
if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8
204 locA = TopLoc_Location (TR1);
217 TDF_Label labelMother;
221 while ((currentNode = nextNode())) {
222 level = nextNode.GetLevel();
225 for (
int i = level; i > 0; i--) {
229 motherNode = nextNode.GetNode(--level);
230 labelMother = GetLabelOfVolume(motherNode->
GetVolume());
232 fLabel = GetLabelOfVolume(currentNode->GetVolume());
233 loc = CalcLocation((*(currentNode->GetMatrix())));
234 if ((XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(labelMother) < ndMother) && (!nd)) {
235 AddChildLabel(labelMother, fLabel, loc);
236 }
else if ((XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(fLabel) == nd) && (XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(labelMother) == motherNode->
GetVolume()->
GetIndex(currentNode))) {
237 AddChildLabel(labelMother, fLabel, loc);
239 currentNode = motherNode;
240 fLabel = labelMother;
251 #if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8 252 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->Dump();
254 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->Dump(std::cout);
virtual const char * GetName() const
Returns name of object.
The manager class for any TGeo geometry.
void OCCWriteStep(const char *fname)
virtual const Double_t * GetRotationMatrix() const
virtual const Double_t * GetTranslation() const
An identity transformation.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
void AddChildLabel(TDF_Label mother, TDF_Label child, TopLoc_Location loc)
TGeoVolume * GetVolumeOfLabel(TDF_Label fLabel)
Matrix class used for computing global transformations Should NOT be used for node definition...
Int_t GetNdaughters() const
void OCCTreeCreation(TGeoManager *m)
void Error(const char *location, const char *msgfmt,...)
Class handling Boolean composition of shapes.
Int_t GetIndex(const TGeoNode *node) const
get index number for a given daughter
TGeoNode * GetTopNode() const
TopLoc_Location CalcLocation(TGeoHMatrix matrix)
TDF_Label OCCShapeCreation(TGeoManager *m)
Logical fTree creation.
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
TObjArray * GetListOfVolumes() const
TDF_Label GetLabelOfVolume(TGeoVolume *v)
Int_t GetNdaughters() const
TGeoVolume * GetTopVolume() const
TGeoShape * GetShape() const
TGeoVolume * GetVolume() const