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;
79 TIter next(
m->GetListOfVolumes());
80 fLabel = XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NewShape();
82 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(
fLabel,
fShape);
83 TDataStd_Name::Set(
fLabel,
m->GetTopVolume()->GetName());
84 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
85 Top =
m->GetTopVolume();
87 while ((currentVolume = (
TGeoVolume *)next())) {
98 while ((current = nextNode())) {
103 motherVol =
m->GetTopVolume();
109 if (!motherLabel.IsNull()) {
110 fLabel = TDF_TagSource::NewChild(motherLabel);
115 TopoDS_Shape Mothershape;
122 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(motherLabel, Mothershape);
123 TDataStd_Name::Set(motherLabel, motherVol->
GetName());
124 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
125 fTree[motherVol] = motherLabel;
126 fLabel = TDF_TagSource::NewChild(motherLabel);
131 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->SetShape(
fLabel,
fShape);
133 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->UpdateAssembly(fDoc->Main());
144 STEPControl_StepModelType mode = STEPControl_AsIs;
145 fWriter.SetNameMode(Standard_True);
146 if (!Interface_Static::SetIVal(
"write.step.assembly", 1)) {
147 Error(
"TOCCToStep::OCCWriteStep",
"failed to set assembly mode for step data");
149 if (!
fWriter.Transfer(fDoc, mode)) {
150 ::Error(
"TOCCToStep::OCCWriteStep",
"error translating document");
170 map <TGeoVolume *,TDF_Label>::iterator it;
171 for(it =
fTree.begin(); it !=
fTree.end(); ++it)
172 if (it->second.IsEqual(
fLabel))
181 XCAFDoc_DocumentTool::ShapeTool(mother)->AddComponent(mother, child,loc);
182 XCAFDoc_DocumentTool::ShapeTool(mother)->UpdateAssembly(mother);
190 TopLoc_Location locA;
193 TR1.SetTranslation(gp_Vec(t[0],t[1],t[2]));
194 TR.SetValues(
r[0],
r[1],
r[2],0,
197#
if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8
202 locA = TopLoc_Location (TR1);
215 TDF_Label labelMother;
219 while ((currentNode = nextNode())) {
221 if( level > max_level ){
230 for (
int i = level; i > 0; i--) {
232 motherNode =
m->GetTopNode();
234 motherNode = nextNode.
GetNode(--level);
240 if ((XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(labelMother) < ndMother) && (!nd)) {
242 }
else if ((XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(
fLabel) == nd) &&
243 (XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(labelMother) == motherNode->
GetVolume()->
GetIndex(currentNode))) {
246 currentNode = motherNode;
258 std::string search_n = node_name;
259 bool found_once =
false;
260 bool found_in_level_1 =
false;
261 auto volume =
m->GetVolume(node_name);
262 int level1_skipped = 0;
266 while ((currentNode = nextNode())) {
269 if( level > max_level ){
273 found_in_level_1 =
false;
274 if( volume == currentNode->
GetVolume() ) {
275 found_in_level_1 =
true;
279 if(!found_in_level_1) {
286 FillOCCWithNode(
m, currentNode, nextNode, level, max_level, level1_skipped);
294 bool found_once =
false;
295 bool found_in_level_1 =
false;
296 int level1_skipped = 0;
298 std::map<TGeoVolume*,std::string> part_name_vols;
299 std::vector<TGeoVolume*> vols;
301 for(
const auto& pl : part_name_levels) {
303 part_name_vols[avol] = pl.first;
304 vols.push_back(avol);
312 while ((currentNode = nextNode())) {
319 found_in_level_1 =
false;
324 found_in_level_1 =
true;
329 if(!found_in_level_1) {
337 int max_level = part_name_levels[ part_name_vols[matched_vol]];
338 if( level > max_level ){
342 FillOCCWithNode(
m, currentNode, nextNode, level, max_level, level1_skipped);
356 if(level == max_level) {
360 int level_start = std::min(level,max_level);
361 for (
int i = level_start; i > 0; i--) {
363 TDF_Label labelMother;
367 motherNode =
m->GetTopNode();
369 motherNode = nextNode.
GetNode(i-1);
377 int skipped_this_level = 0;
378 if(i == 1 ) skipped_this_level = level1_skipped;
379 if ((XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(labelMother) < ndMother) && (!nd)) {
382 }
else if ((XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(
fLabel) == currentNode->
GetNdaughters()) &&
383 (XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->NbComponents(labelMother)+skipped_this_level == motherNode->
GetVolume()->
GetIndex(currentNode))) {
386 currentNode = motherNode;
396#if OCC_VERSION_MAJOR == 6 && OCC_VERSION_MINOR < 8
397 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->Dump();
399 XCAFDoc_DocumentTool::ShapeTool(fDoc->Main())->Dump(std::cout);
void Error(const char *location, const char *msgfmt,...)
Class handling Boolean composition of shapes.
Matrix class used for computing global transformations Should NOT be used for node definition.
virtual const Double_t * GetTranslation() const
virtual const Double_t * GetRotationMatrix() const
An identity transformation.
void GetPath(TString &path) const
Returns the path for the current node.
TGeoNode * GetNode(Int_t level) const
Returns current node at a given level.
The manager class for any TGeo geometry.
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
TGeoVolume * GetVolume() const
Int_t GetNdaughters() const
virtual TGeoMatrix * GetMatrix() const =0
TopoDS_Shape OCC_CompositeShape(TGeoCompositeShape *cs, TGeoHMatrix matrix)
TopoDS_Shape OCC_SimpleShape(TGeoShape *TG_Shape)
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Int_t GetIndex(const TGeoNode *node) const
get index number for a given daughter
TGeoShape * GetShape() const
virtual const char * GetName() const
Returns name of object.
STEPCAFControl_Writer fWriter
TGeoVolume * GetVolumeOfLabel(TDF_Label fLabel)
TopLoc_Location CalcLocation(TGeoHMatrix matrix)
bool OCCPartialTreeCreation(TGeoManager *m, const char *node_name, int max_level=-1)
Handle(TDocStd_Document) fDoc
void OCCWriteStep(const char *fname)
TDF_Label GetLabelOfVolume(TGeoVolume *v)
void FillOCCWithNode(TGeoManager *m, TGeoNode *currentNode, TGeoIterator &nextNode, int level, int max_level, int level1_skipped)
TDF_Label OCCShapeCreation(TGeoManager *m)
Logical fTree creation.
void AddChildLabel(TDF_Label mother, TDF_Label child, TopLoc_Location loc)
void OCCTreeCreation(TGeoManager *m, int max_level=-1)