39 #include <Interface_Static.hxx> 40 #include <BRepBuilderAPI_Transform.hxx> 41 #include <TDataStd_Name.hxx> 42 #include <XCAFDoc_DocumentTool.hxx> 43 #include <Standard.hxx> 45 #include <XCAFApp_Application.hxx> 61 Handle (XCAFApp_Application)
A = XCAFApp_Application::GetApplication();
63 A->NewDocument (
"MDTV-XCAF", fDoc);
66 ::Error(
"TOCCToStep::OCCDocCreation",
"creating OCC application");
74 TDF_Label motherLabel;
82 fLabel = XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NewShape();
84 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(fLabel, fShape);
86 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
89 while ((currentVolume = (
TGeoVolume *)next())) {
90 if (GetLabelOfVolume(currentVolume).IsNull()) {
92 if ((GetLabelOfVolume(currentVolume).IsNull())) {
96 fShape = fRootShape.OCC_SimpleShape(currentVolume->
GetShape());
101 while ((current = nextNode())) {
102 if ((current->
GetVolume() == currentVolume) && (GetLabelOfVolume(current->
GetVolume()).IsNull())) {
104 nextNode.GetPath(path);
108 TGeoNode * mother = nextNode.GetNode(--level);
111 motherLabel = GetLabelOfVolume(motherVol);
112 if (!motherLabel.IsNull()) {
113 fLabel = TDF_TagSource::NewChild(motherLabel);
116 TGeoNode * grandMother = nextNode.GetNode(level);
118 TopoDS_Shape Mothershape;
122 Mothershape = fRootShape.OCC_SimpleShape(motherVol->
GetShape());
124 motherLabel = TDF_TagSource::NewChild(GetLabelOfVolume(Top));
125 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(motherLabel, Mothershape);
126 TDataStd_Name::Set(motherLabel, motherVol->
GetName());
127 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
128 fTree[motherVol] = motherLabel;
129 fLabel = TDF_TagSource::NewChild(motherLabel);
134 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(fLabel, fShape);
135 TDataStd_Name::Set(fLabel, currentVolume->
GetName());
136 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
137 fTree[currentVolume] = fLabel;
147 STEPControl_StepModelType mode = STEPControl_AsIs;
148 fWriter.SetNameMode(Standard_True);
149 if (!Interface_Static::SetIVal(
"write.step.assembly", 1)) {
150 Error(
"TOCCToStep::OCCWriteStep",
"failed to set assembly mode for step data");
152 if (!fWriter.Transfer(fDoc, mode)) {
153 ::Error(
"TOCCToStep::OCCWriteStep",
"error translating document");
155 fWriter.Write(fname);
163 if (fTree.find(v) != fTree.end())
173 map <TGeoVolume *,TDF_Label>::iterator it;
174 for(it = fTree.begin(); it != fTree.end(); it++)
175 if (it->second.IsEqual(fLabel))
184 XCAFDoc_DocumentTool::ShapeTool(mother)->AddComponent(mother, child,loc);
185 XCAFDoc_DocumentTool::ShapeTool(mother)->UpdateAssembly(mother);
193 TopLoc_Location locA;
196 TR1.SetTranslation(gp_Vec(t[0],t[1],t[2]));
197 TR.SetValues(r[0],r[1],r[2],0,
200 #
if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8
205 locA = TopLoc_Location (TR1);
218 TDF_Label labelMother;
222 while ((currentNode = nextNode())) {
223 level = nextNode.GetLevel();
226 for (
int i = level; i > 0; i--) {
230 motherNode = nextNode.GetNode(--level);
231 labelMother = GetLabelOfVolume(motherNode->
GetVolume());
233 fLabel = GetLabelOfVolume(currentNode->GetVolume());
234 loc = CalcLocation((*(currentNode->GetMatrix())));
235 if ((XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(labelMother) < ndMother) && (!nd)) {
236 AddChildLabel(labelMother, fLabel, loc);
237 }
else if ((XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(fLabel) == nd) && (XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(labelMother) == motherNode->
GetVolume()->
GetIndex(currentNode))) {
238 AddChildLabel(labelMother, fLabel, loc);
240 currentNode = motherNode;
241 fLabel = labelMother;
252 #if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8 253 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->Dump();
255 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