1 // Created on: 2000-08-04
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <XDEDRAW.ixx>
24 #include <TCollection_ExtendedString.hxx>
25 #include <TCollection_AsciiString.hxx>
26 #include <TColStd_HSequenceOfExtendedString.hxx>
27 #include <TCollection_HAsciiString.hxx>
28 #include <Quantity_Color.hxx>
30 #include <TopoDS_Shape.hxx>
34 #include <V3d_Viewer.hxx>
35 #include <V3d_View.hxx>
36 #include <AIS_InteractiveContext.hxx>
37 #include <ViewerTest_Tool.hxx>
39 #include <DDF_Browser.hxx>
40 #include <DDocStd.hxx>
41 #include <DDocStd_DrawDocument.hxx>
43 #include <STEPCAFControl_Controller.hxx>
45 #include <TDF_Tool.hxx>
46 #include <TDF_Data.hxx>
47 #include <TDF_LabelSequence.hxx>
48 #include <TDF_AttributeIterator.hxx>
49 #include <TDF_Reference.hxx>
50 #include <TDocStd_Document.hxx>
51 #include <TDataStd_UAttribute.hxx>
52 #include <TDataStd_TreeNode.hxx>
53 #include <TDataStd_Integer.hxx>
54 #include <TDataStd_Real.hxx>
55 #include <TDataStd_Name.hxx>
56 #include <TDataStd_Comment.hxx>
57 #include <TDataStd_AsciiString.hxx>
58 #include <TNaming_NamedShape.hxx>
59 #include <TDataStd_IntegerArray.hxx>
60 #include <TDataStd_RealArray.hxx>
61 #include <TDataStd_ByteArray.hxx>
62 #include <TPrsStd_AISPresentation.hxx>
63 #include <TPrsStd_NamedShapeDriver.hxx>
64 #include <TPrsStd_AISViewer.hxx>
66 #include <XCAFDoc.hxx>
67 #include <XCAFDoc_Color.hxx>
68 #include <XCAFDoc_Volume.hxx>
69 #include <XCAFDoc_Area.hxx>
70 #include <XCAFDoc_Centroid.hxx>
71 #include <XCAFDoc_ShapeTool.hxx>
72 #include <XCAFDoc_ColorTool.hxx>
73 #include <XCAFDoc_DocumentTool.hxx>
74 #include <XCAFDoc_GraphNode.hxx>
75 #include <XCAFDoc_LayerTool.hxx>
76 #include <XCAFDoc_DimTol.hxx>
77 #include <XCAFDoc_Material.hxx>
78 #include <XCAFPrs_Driver.hxx>
79 #include <XCAFApp_Application.hxx>
81 #include <XDEDRAW_Shapes.hxx>
82 #include <XDEDRAW_Colors.hxx>
83 #include <XDEDRAW_Layers.hxx>
84 #include <XDEDRAW_Props.hxx>
85 #include <XDEDRAW_Common.hxx>
86 #include <XSDRAWIGES.hxx>
87 #include <XSDRAWSTEP.hxx>
90 #include <XCAFPrs.hxx>
91 #include <ViewerTest.hxx>
92 #include <Draw_PluginMacro.hxx>
94 #include <TColStd_HArray1OfInteger.hxx>
95 #include <TColStd_HArray1OfReal.hxx>
97 #include <AIS_InteractiveObject.hxx>
98 #include <AIS_Drawer.hxx>
99 #include <Aspect_TypeOfLine.hxx>
100 #include <Prs3d_LineAspect.hxx>
101 #include <TDocStd_Owner.hxx>
102 #include <Geom_Axis2Placement.hxx>
103 #include <AIS_Trihedron.hxx>
105 #define ZVIEW_SIZE 1000000.0
106 // avoid warnings on 'extern "C"' functions returning C++ classes
108 #pragma warning(4:4190)
111 //=======================================================================
112 // Section: General commands
113 //=======================================================================
115 //=======================================================================
118 //=======================================================================
119 static Standard_Integer newDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
121 if (argc < 2) {di<<"Give document name"<<"\n";return 1;}
123 Handle(TDocStd_Document) D;
124 Handle(DDocStd_DrawDocument) DD;
125 Handle(TDocStd_Application) A;
127 if (!DDocStd::Find(A)) return 1;
129 if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
130 A->NewDocument( "MDTV-XCAF" ,D);
131 DD = new DDocStd_DrawDocument(D);
132 TDataStd_Name::Set(D->GetData()->Root(),argv[1]);
133 Draw::Set(argv[1],DD);
134 di << "document " << argv[1] << " created" << "\n";
135 //DDocStd::ReturnLabel(di,D->Main());
137 else di << argv[1] << " is already a document" << "\n";
143 //=======================================================================
146 //=======================================================================
147 static Standard_Integer saveDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
149 Handle(TDocStd_Document) D;
150 Handle(TDocStd_Application) A;
151 if (!DDocStd::Find(A)) return 1;
154 if (A->NbDocuments() < 1) return 1;
155 A->GetDocument(1, D);
158 if (!DDocStd::GetDocument(argv[1],D)) return 1;
162 TCollection_ExtendedString path (argv[2]);
167 di << "this document has never been saved" << "\n";
174 //=======================================================================
177 //=======================================================================
178 static Standard_Integer openDoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
180 Handle(TDocStd_Document) D;
181 Handle(DDocStd_DrawDocument) DD;
182 Handle(TDocStd_Application) A;
184 if ( !DDocStd::Find(A) )
189 di << "invalid number of arguments. Usage:\t XOpen filename docname" << "\n";
193 Standard_CString Filename = argv[1];
194 Standard_CString DocName = argv[2];
196 if ( DDocStd::GetDocument(DocName, D, Standard_False) )
198 di << "document with name " << DocName << " already exists" << "\n";
202 if ( A->Open(Filename, D) != PCDM_RS_OK )
204 di << "cannot open XDE document" << "\n";
208 DD = new DDocStd_DrawDocument(D);
209 TDataStd_Name::Set(D->GetData()->Root(), DocName);
210 Draw::Set(DocName, DD);
212 di << "document " << DocName << " opened" << "\n";
217 //=======================================================================
220 //=======================================================================
221 static Standard_Integer dump (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
224 di<<"Use: "<<argv[0]<<" Doc [int deep (0/1)]"<<"\n";
227 Handle(TDocStd_Document) Doc;
228 DDocStd::GetDocument(argv[1], Doc);
229 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
231 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
232 Standard_Boolean deep = Standard_False;
233 if ( (argc==3) && (Draw::Atoi(argv[2])==1) ) deep = Standard_True;
234 myAssembly->Dump(deep);
239 //=======================================================================
240 //function : StatAssembly
241 //purpose : recursive part of statistics
242 //=======================================================================
244 static void StatAssembly(const TDF_Label L,
245 const Standard_Integer level,
246 Handle(TColStd_HArray1OfInteger) &HAI,
247 Standard_Integer &NbCentroidProp,
248 Standard_Integer &NbVolumeProp,
249 Standard_Integer &NbAreaProp,
250 Standard_Integer &NbShapesWithName,
251 Standard_Integer &NbShapesWithColor,
252 Standard_Integer &NbShapesWithLayer,
253 Handle(TDocStd_Document) &aDoc,
254 Standard_Boolean &PrintStructMode,
255 Draw_Interpretor& di)
257 if(PrintStructMode) {
258 for(Standard_Integer j=0; j<=level; j++)
261 TCollection_AsciiString Entry;
262 TDF_Tool::Entry(L, Entry);
263 if(PrintStructMode) di<<Entry.ToCString();
265 Handle(TDataStd_Name) Name;
266 if(L.FindAttribute(TDataStd_Name::GetID(), Name)) {
268 if(PrintStructMode) {
269 TCollection_AsciiString AsciiStringName(Name->Get(),'?');
270 di<<" "<<AsciiStringName.ToCString()<<" has attributes: ";
274 if(PrintStructMode) di<<" NoName has attributes: ";
277 Handle(XCAFDoc_Centroid) aCentroid = new (XCAFDoc_Centroid);
278 if(L.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid)) {
279 if(PrintStructMode) di<<"Centroid ";
283 if(XCAFDoc_Volume::Get(L,tmp)) {
284 if(PrintStructMode) di<<"Volume("<<tmp<<") ";
287 if(XCAFDoc_Area::Get(L,tmp)) {
288 if(PrintStructMode) di<<"Area("<<tmp<<") ";
291 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
293 Standard_Boolean IsColor = Standard_False;
294 if(CTool->GetColor(L,XCAFDoc_ColorGen,col))
295 IsColor = Standard_True;
296 else if(CTool->GetColor(L,XCAFDoc_ColorSurf,col))
297 IsColor = Standard_True;
298 else if(CTool->GetColor(L,XCAFDoc_ColorCurv,col))
299 IsColor = Standard_True;
301 TCollection_AsciiString Entry1;
302 Entry1 = col.StringName(col.Name());
303 if(PrintStructMode) di<<"Color("<<Entry1.ToCString()<<") ";
306 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(aDoc->Main());
307 Handle(TColStd_HSequenceOfExtendedString) aLayerS;
308 LTool->GetLayers(L, aLayerS);
309 if(!aLayerS.IsNull() && aLayerS->Length()>0) {
310 if(PrintStructMode) {
312 for(Standard_Integer i=1; i<=aLayerS->Length(); i++) {
313 TCollection_AsciiString Entry2(aLayerS->Value(i),'?');
315 di<<"\""<<Entry2.ToCString()<<"\"";
317 di<<" "<<"\""<<Entry2.ToCString()<<"\"";
323 if(PrintStructMode) di<<"\n";
325 HAI->SetValue(level, HAI->Value(level)+1 );
327 for(Standard_Integer i=1; i<=L.NbChildren(); i++) {
328 StatAssembly(L.FindChild(i), level+1, HAI, NbCentroidProp, NbVolumeProp,
329 NbAreaProp, NbShapesWithName, NbShapesWithColor,
330 NbShapesWithLayer, aDoc, PrintStructMode, di);
337 //=======================================================================
340 //=======================================================================
341 static Standard_Integer statdoc (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
344 di<<"Use: "<<argv[0]<<" Doc "<<"\n";
347 Handle(TDocStd_Document) Doc;
348 DDocStd::GetDocument(argv[1], Doc);
349 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
351 Standard_Boolean PrintStructMode = (argc==3);
352 Handle(XCAFDoc_ShapeTool) aTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
354 TDF_LabelSequence SeqLabels;
355 aTool->GetShapes(SeqLabels);
356 if(SeqLabels.Length()<=0) return 0;
357 if(PrintStructMode) di<<"\n"<<"Structure of shapes in the document:"<<"\n";
358 Standard_Integer level=0;
359 Standard_Integer NbCentroidProp=0, NbVolumeProp=0, NbAreaProp=0;
360 Standard_Integer NbShapesWithName=0, NbShapesWithColor=0, NbShapesWithLayer=0;
361 Handle(TColStd_HArray1OfInteger) HAI = new TColStd_HArray1OfInteger(0,20);
362 Standard_Integer i=0;
363 for(i=0; i<=20; i++) HAI->SetValue(i,0);
364 for(i=1; i<=SeqLabels.Length(); i++) {
365 StatAssembly(SeqLabels.Value(i), level, HAI, NbCentroidProp, NbVolumeProp,
366 NbAreaProp, NbShapesWithName, NbShapesWithColor,
367 NbShapesWithLayer, Doc, PrintStructMode, di);
369 Standard_Integer NbLabelsShape = 0;
370 di<<"\n"<<"Statistis of shapes in the document:"<<"\n";
371 for(i=0; i<=20; i++) {
372 if(HAI->Value(i)==0) break;
373 //di<<"level N "<<i<<" : number of labels with shape = "<<HAI->Value(i)<<"\n";
374 di<<"level N "<<i<<" : "<<HAI->Value(i)<<"\n";
375 NbLabelsShape = NbLabelsShape + HAI->Value(i);
377 di<<"Total number of labels for shapes in the document = "<<NbLabelsShape<<"\n";
378 di<<"Number of labels with name = "<<NbShapesWithName<<"\n";
379 di<<"Number of labels with color link = "<<NbShapesWithColor<<"\n";
380 di<<"Number of labels with layer link = "<<NbShapesWithLayer<<"\n";
382 di<<"\n"<<"Statistis of Props in the document:"<<"\n";
383 di<<"Number of Centroid Props = "<<NbCentroidProp<<"\n";
384 di<<"Number of Volume Props = "<<NbVolumeProp<<"\n";
385 di<<"Number of Area Props = "<<NbAreaProp<<"\n";
387 Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
388 TDF_LabelSequence CLabels;
389 CTool->GetColors(CLabels);
390 di<<"\n"<<"Number of colors = "<<CLabels.Length()<<"\n";
391 if(CLabels.Length()>0) {
392 for(i=1; i<=CLabels.Length(); i++) {
393 TDF_Label aLabel = CLabels.Value(i);
395 CTool->GetColor(aLabel, col);
396 di<<col.StringName(col.Name())<<" ";
401 Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main());
402 TDF_LabelSequence LLabels;
403 LTool->GetLayerLabels(LLabels);
404 di<<"\n"<<"Number of layers = "<<LLabels.Length()<<"\n";
405 if(LLabels.Length()>0) {
406 for(i=1; i<=LLabels.Length(); i++) {
407 TDF_Label aLabel = LLabels.Value(i);
408 TCollection_ExtendedString layerName;
409 LTool->GetLayer(aLabel, layerName);
410 TCollection_AsciiString Entry(layerName,'?');
411 di<<"\""<<Entry.ToCString() <<"\" ";
421 //=======================================================================
424 //=======================================================================
425 static Standard_Integer setPrs (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
428 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
432 Handle(TDocStd_Document) Doc;
433 DDocStd::GetDocument(argv[1], Doc);
434 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
436 // collect sequence of labels to set presentation
437 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
438 TDF_LabelSequence seq;
440 for ( Standard_Integer i=2; i < argc; i++ ) {
442 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
443 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
444 di << argv[i] << " is not a valid shape label!";
447 seq.Append ( aLabel );
451 shapes->GetShapes ( seq );
455 Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
456 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
457 Handle(TPrsStd_AISPresentation) prs;
458 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
459 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
460 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
462 // Quantity_Color Col;
463 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
464 // prs->SetColor ( Col.Name() );
465 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
466 // prs->SetColor ( Col.Name() );
472 //=======================================================================
475 //=======================================================================
476 static Standard_Integer show (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
479 di<<"Use: "<<argv[0]<<" DocName [label1 label2 ...] "<<"\n";
483 Handle(TDocStd_Document) Doc;
484 DDocStd::GetDocument(argv[1], Doc);
485 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
489 // Sprintf ( string, "AISInitViewer %s", argv[1] );
490 // di.Eval ( string );
491 TDF_Label acces = Doc->GetData()->Root();
492 Handle(TPrsStd_AISViewer) viewer;
493 if (!TPrsStd_AISViewer::Find (acces,viewer)) {
494 TCollection_AsciiString title;
495 title.Prepend(argv[1]);
497 title.Prepend("Document");
498 Handle(V3d_Viewer) vw=ViewerTest_Tool::MakeViewer (title.ToCString());
499 viewer = TPrsStd_AISViewer::New (acces,vw);
501 ViewerTest_Tool::InitViewerTest (viewer->GetInteractiveContext());
503 //szv:CAX-TRJ7 c2-pe-214.stp was clipped
504 viewer->GetInteractiveContext()->CurrentViewer()->ActiveView()->SetZSize(ZVIEW_SIZE);
505 //DDF::ReturnLabel(di,viewer->Label());
507 // collect sequence of labels to display
508 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
509 TDF_LabelSequence seq;
511 for ( Standard_Integer i=2; i < argc; i++ ) {
513 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
514 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
515 di << argv[i] << " is not a valid shape label!";
518 seq.Append ( aLabel );
522 shapes->GetFreeShapes ( seq );
525 // set presentations and show
526 //Handle(XCAFDoc_ColorTool) colors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
527 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
528 Handle(TPrsStd_AISPresentation) prs;
529 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
530 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
531 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
533 // Quantity_Color Col;
534 // if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorSurf, Col ) )
535 // prs->SetColor ( Col.Name() );
536 // else if ( colors.GetColor ( seq.Value(i), XCAFDoc_ColorCurv, Col ) )
537 // prs->SetColor ( Col.Name() );
538 prs->Display(Standard_True);
540 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
545 //=======================================================================
548 //=======================================================================
549 static Standard_Integer xwd (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
552 di<<"Use: "<<argv[0]<<" DocName filename.{xwd|gif|bmp}"<<"\n";
556 Handle(TDocStd_Document) Doc;
557 DDocStd::GetDocument(argv[1], Doc);
558 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
560 Handle(AIS_InteractiveContext) IC;
561 if ( ! TPrsStd_AISViewer::Find ( Doc->GetData()->Root(), IC ) ) {
562 di << "Cannot find viewer for document " << argv[1] << "\n";
566 Handle(V3d_Viewer) viewer = IC->CurrentViewer();
567 viewer->InitActiveViews();
568 if ( viewer->MoreActiveViews() ) {
569 viewer->ActiveView()->Dump ( argv[2] );
572 di << "Cannot find an active view in a viewer " << argv[1] << "\n";
580 //=======================================================================
581 //function : XAttributeValue
583 //=======================================================================
584 static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
586 if ( argc <4 ) { di << "ERROR: Too few args" << "\n"; return 0; }
587 Handle(DDF_Browser) browser =
588 Handle(DDF_Browser)::DownCast (Draw::Get(argv[1], Standard_True));
589 if ( browser.IsNull() ) { di << "ERROR: Not a browser: " << argv[1] << "\n"; return 0; }
592 TDF_Tool::Label(browser->Data(),argv[2],lab);
593 if ( lab.IsNull() ) { di << "ERROR: label is Null: " << argv[2] << "\n"; return 0; }
595 Standard_Integer num = Draw::Atoi ( argv[3] );
596 TDF_AttributeIterator itr(lab,Standard_False);
597 for (Standard_Integer i=1; itr.More() && i < num; i++) itr.Next();
599 if ( ! itr.More() ) { di << "ERROR: Attribute #" << num << " not found" << "\n"; return 0; }
601 const Handle(TDF_Attribute)& att = itr.Value();
602 if ( att->IsKind(STANDARD_TYPE(TDataStd_TreeNode)) ) {
603 Standard_CString type = "";
604 if ( att->ID() == XCAFDoc::ShapeRefGUID() ) type = "Shape Instance Link";
605 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen) ) type = "Generic Color Link";
606 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf) ) type = "Surface Color Link";
607 else if ( att->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv) ) type = "Curve Color Link";
608 else if ( att->ID() == XCAFDoc::DimTolRefGUID() ) type = "DGT Link";
609 else if ( att->ID() == XCAFDoc::DatumRefGUID() ) type = "Datum Link";
610 else if ( att->ID() == XCAFDoc::MaterialRefGUID() ) type = "Material Link";
611 Handle(TDataStd_TreeNode) TN = Handle(TDataStd_TreeNode)::DownCast(att);
612 TCollection_AsciiString ref;
613 if ( TN->HasFather() ) {
614 TDF_Tool::Entry ( TN->Father()->Label(), ref );
615 di << type << " ==> " << ref.ToCString();
618 di << type << " <== (" << ref.ToCString();
619 Handle(TDataStd_TreeNode) child = TN->First();
620 while ( ! child.IsNull() ) {
621 TDF_Tool::Entry ( child->Label(), ref );
622 if ( child != TN->First() ) di << ", ";
623 di << ref.ToCString();
624 child = child->Next();
629 else if ( att->IsKind(STANDARD_TYPE(TDF_Reference)) ) {
630 Handle(TDF_Reference) val = Handle(TDF_Reference)::DownCast ( att );
631 TCollection_AsciiString ref;
632 TDF_Tool::Entry ( val->Get(), ref );
633 di << "==> " << ref.ToCString();
635 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Integer)) ) {
636 Handle(TDataStd_Integer) val = Handle(TDataStd_Integer)::DownCast ( att );
637 TCollection_AsciiString str ( val->Get() );
638 di << str.ToCString();
640 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Real)) ) {
641 Handle(TDataStd_Real) val = Handle(TDataStd_Real)::DownCast ( att );
642 TCollection_AsciiString str ( val->Get() );
643 di << str.ToCString();
645 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Name)) ) {
646 Handle(TDataStd_Name) val = Handle(TDataStd_Name)::DownCast ( att );
647 TCollection_AsciiString str ( val->Get(), '?' );
648 di << str.ToCString();
650 else if ( att->IsKind(STANDARD_TYPE(TDataStd_Comment)) ) {
651 Handle(TDataStd_Comment) val = Handle(TDataStd_Comment)::DownCast ( att );
652 TCollection_AsciiString str ( val->Get(), '?' );
653 di << str.ToCString();
655 else if ( att->IsKind(STANDARD_TYPE(TDataStd_AsciiString)) ) {
656 Handle(TDataStd_AsciiString) val = Handle(TDataStd_AsciiString)::DownCast ( att );
657 TCollection_AsciiString str ( val->Get(), '?' );
658 di << str.ToCString();
660 else if ( att->IsKind(STANDARD_TYPE(TDataStd_IntegerArray)) ) {
661 Handle(TDataStd_IntegerArray) val = Handle(TDataStd_IntegerArray)::DownCast ( att );
662 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
663 if ( j > val->Lower() ) di << ", ";
664 TCollection_AsciiString str ( val->Value(j) );
665 di << str.ToCString();
668 else if ( att->IsKind(STANDARD_TYPE(TDataStd_RealArray)) ) {
669 Handle(TDataStd_RealArray) val = Handle(TDataStd_RealArray)::DownCast ( att );
670 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
671 if ( j > val->Lower() ) di << ", ";
672 TCollection_AsciiString str ( val->Value(j) );
673 di << str.ToCString();
676 else if ( att->IsKind(STANDARD_TYPE(TDataStd_ByteArray)) ) {
677 Handle(TDataStd_ByteArray) val = Handle(TDataStd_ByteArray)::DownCast ( att );
678 for ( Standard_Integer j=val->Lower(); j <= val->Upper(); j++ ) {
679 if ( j > val->Lower() ) di << ", ";
680 TCollection_AsciiString str ( val->Value(j) );
681 di << str.ToCString();
684 else if ( att->IsKind(STANDARD_TYPE(TNaming_NamedShape)) ) {
685 Handle(TNaming_NamedShape) val = Handle(TNaming_NamedShape)::DownCast ( att );
686 TopoDS_Shape S = val->Get();
687 di << S.TShape()->DynamicType()->Name();
688 if ( ! S.Location().IsIdentity() ) di << "(located)";
690 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Volume)) ) {
691 Handle(XCAFDoc_Volume) val = Handle(XCAFDoc_Volume)::DownCast ( att );
692 TCollection_AsciiString str ( val->Get() );
693 di << str.ToCString();
695 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Area)) ) {
696 Handle(XCAFDoc_Area) val = Handle(XCAFDoc_Area)::DownCast ( att );
697 TCollection_AsciiString str ( val->Get() );
698 di << str.ToCString();
700 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Centroid)) ) {
701 Handle(XCAFDoc_Centroid) val = Handle(XCAFDoc_Centroid)::DownCast ( att );
702 gp_Pnt myCentroid = val->Get();
704 di << myCentroid.X();
706 di << myCentroid.Y();
708 di << myCentroid.Z();
711 else if ( att->IsKind(STANDARD_TYPE(TDataStd_UAttribute)) ) {
712 if ( att->ID() == XCAFDoc::AssemblyGUID() ) di << "is assembly";
713 if ( att->ID() == XCAFDoc::InvisibleGUID() ) di << "invisible";
715 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Color)) ) {
716 Handle(XCAFDoc_Color) val = Handle(XCAFDoc_Color)::DownCast ( att );
717 Quantity_Color C = val->GetColor();
719 Sprintf ( string, "%s (%g, %g, %g)", C.StringName ( C.Name() ),
720 C.Red(), C.Green(), C.Blue() );
723 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_DimTol)) ) {
724 Handle(XCAFDoc_DimTol) val = Handle(XCAFDoc_DimTol)::DownCast ( att );
725 Standard_Integer kind = val->GetKind();
726 Handle(TColStd_HArray1OfReal) HAR = val->GetVal();
727 if(kind<20) { //dimension
728 di<<"Diameter (ValueRange["<<HAR->Value(1)<<","<<HAR->Value(2)<<"])";
732 case 21: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_1 (Value="<<HAR->Value(1)<<")"; break;
733 case 22: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_2 (Value="<<HAR->Value(1)<<")"; break;
734 case 23: di << "GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol_3 (Value="<<HAR->Value(1)<<")"; break;
735 case 24: di << "AngularityTolerance (Value="<<HAR->Value(1)<<")"; break;
736 case 25: di << "CircularRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
737 case 26: di << "CoaxialityTolerance (Value="<<HAR->Value(1)<<")"; break;
738 case 27: di << "ConcentricityTolerance (Value="<<HAR->Value(1)<<")"; break;
739 case 28: di << "ParallelismTolerance (Value="<<HAR->Value(1)<<")"; break;
740 case 29: di << "PerpendicularityTolerance (Value="<<HAR->Value(1)<<")"; break;
741 case 30: di << "SymmetryTolerance (Value="<<HAR->Value(1)<<")"; break;
742 case 31: di << "TotalRunoutTolerance (Value="<<HAR->Value(1)<<")"; break;
743 case 35: di << "ModifiedGeometricTolerance_1 (Value="<<HAR->Value(1)<<")"; break;
744 case 36: di << "ModifiedGeometricTolerance_2 (Value="<<HAR->Value(1)<<")"; break;
745 case 37: di << "ModifiedGeometricTolerance_3 (Value="<<HAR->Value(1)<<")"; break;
746 case 38: di << "CylindricityTolerance (Value="<<HAR->Value(1)<<")"; break;
747 case 39: di << "FlatnessTolerance (Value="<<HAR->Value(1)<<")"; break;
748 case 40: di << "LineProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
749 case 41: di << "PositionTolerance (Value="<<HAR->Value(1)<<")"; break;
750 case 42: di << "RoundnessTolerance (Value="<<HAR->Value(1)<<")"; break;
751 case 43: di << "StraightnessTolerance (Value="<<HAR->Value(1)<<")"; break;
752 case 44: di << "SurfaceProfileTolerance (Value="<<HAR->Value(1)<<")"; break;
756 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_Material)) ) {
757 Handle(XCAFDoc_Material) val = Handle(XCAFDoc_Material)::DownCast ( att );
758 Standard_Real dens = val->GetDensity();
759 Standard_CString dimdens = "g/cu sm";
761 di<<val->GetName()->ToCString();
763 di<<val->GetName()->ToCString()<<"(density="<<dens<<dimdens<<")";
765 else if ( att->IsKind(STANDARD_TYPE(XCAFDoc_GraphNode)) ) {
766 Standard_CString type;
767 if ( att->ID() == XCAFDoc::LayerRefGUID() ) {
768 type = "Layer Instance Link";
770 else if ( att->ID() == XCAFDoc::SHUORefGUID() ) {
771 type = "SHUO Instance Link";
773 else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) {
774 type = "DatumToler Link";
778 Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
779 TCollection_AsciiString ref;
780 Standard_Integer ii = 1;
781 if (DETGN->NbFathers()!=0) {
783 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
784 di << type<< " ==> (" << ref.ToCString();
785 for (ii = 2; ii <= DETGN->NbFathers(); ii++) {
786 TDF_Tool::Entry ( DETGN->GetFather(ii)->Label(), ref );
787 di << ", " << ref.ToCString();
792 if (DETGN->NbChildren()!=0) {
793 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
794 di << type<< " <== (" << ref.ToCString();
795 for (ii = 2; ii <= DETGN->NbChildren(); ii++) {
796 TDF_Tool::Entry ( DETGN->GetChild(ii)->Label(), ref );
797 di << ", " << ref.ToCString();
806 //=======================================================================
807 //function : setviewName
809 //=======================================================================
810 static Standard_Integer setviewName (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
813 di<<"Use: "<<argv[0]<<" (1/0)"<<"\n";
816 Standard_Boolean mode = Standard_False;
817 if (Draw::Atoi(argv[1]) == 1) mode = Standard_True;
818 XCAFPrs::SetViewNameMode(mode);
823 //=======================================================================
824 //function : getviewName
826 //=======================================================================
828 static Standard_Integer getviewName (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
830 if ( XCAFPrs::GetViewNameMode() ) di << "Display names ON"<< "\n";
831 else di << "Display names OFF"<< "\n";
836 //=======================================================================
837 //function : XSetTransparency
839 //=======================================================================
840 static Standard_Integer XSetTransparency (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
843 di<<"Use: "<<argv[0]<<" Doc Transparency [label1 label2 ...] "<<"\n";
847 Handle(TDocStd_Document) Doc;
848 DDocStd::GetDocument(argv[1], Doc);
849 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
851 const Standard_Real aTransparency = Draw::Atof(argv[2]);
853 // collect sequence of labels
854 Handle(XCAFDoc_ShapeTool) shapes = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
855 TDF_LabelSequence seq;
857 for ( Standard_Integer i=3; i < argc; i++ ) {
859 TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
860 if ( aLabel.IsNull() || ! shapes->IsShape ( aLabel ) ) {
861 di << argv[i] << " is not a valid shape label!";
864 seq.Append ( aLabel );
868 shapes->GetFreeShapes ( seq );
871 // find presentations and set transparency
872 for ( Standard_Integer i=1; i <= seq.Length(); i++ ) {
873 Handle(TPrsStd_AISPresentation) prs;
874 if ( ! seq.Value(i).FindAttribute ( TPrsStd_AISPresentation::GetID(), prs ) ) {
875 prs = TPrsStd_AISPresentation::Set(seq.Value(i),XCAFPrs_Driver::GetID());
876 prs->SetMaterial ( Graphic3d_NOM_PLASTIC );
878 prs->SetTransparency( aTransparency );
880 TPrsStd_AISViewer::Update(Doc->GetData()->Root());
884 //=======================================================================
885 //function : XShowFaceBoundary
886 //purpose : Set face boundaries on/off
887 //=======================================================================
888 static Standard_Integer XShowFaceBoundary (Draw_Interpretor& di,
889 Standard_Integer argc,
892 if (( argc != 4 && argc < 7 ) || argc > 9)
894 di << "Usage :\n " << argv[0]
895 << " Doc Label IsOn [R G B [LineWidth [LineStyle]]]\n"
896 << " Doc - is the document name. \n"
897 << " Label - is the shape label. \n"
898 << " IsOn - flag indicating whether the boundaries\n"
899 << " should be turned on or off (can be set\n"
900 << " to 0 (off) or 1 (on)).\n"
901 << " R, G, B - red, green and blue components of boundary\n"
902 << " color in range (0 - 255).\n"
903 << " (default is (0, 0, 0)\n"
904 << " LineWidth - line width\n"
905 << " (default is 1)\n"
906 << " LineStyle - line fill style :\n"
911 << " (default is solid)";
916 // get specified document
917 Handle(TDocStd_Document) aDoc;
918 DDocStd::GetDocument (argv[1], aDoc);
921 di << argv[1] << " is not a document" << "\n";
925 Handle(AIS_InteractiveContext) aContext;
926 if (!TPrsStd_AISViewer::Find (aDoc->GetData()->Root(), aContext))
928 di << "Cannot find viewer for document " << argv[1] << "\n";
932 // get shape tool for shape verification
933 Handle(XCAFDoc_ShapeTool) aShapes =
934 XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
936 // get label and validate that it is a shape label
938 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
939 if (aLabel.IsNull() || !aShapes->IsShape (aLabel))
941 di << argv[2] << " is not a valid shape label!";
945 // get presentation from label
946 Handle(TPrsStd_AISPresentation) aPrs;
947 if (!aLabel.FindAttribute (TPrsStd_AISPresentation::GetID (), aPrs))
949 aPrs = TPrsStd_AISPresentation::Set (aLabel,XCAFPrs_Driver::GetID ());
952 Handle(AIS_InteractiveObject) anInteractive = aPrs->GetAIS ();
953 if (anInteractive.IsNull ())
955 di << "Can't set drawer attributes.\n"
956 "Interactive object for shape label doesn't exists.";
961 const Handle(AIS_Drawer)& aDrawer = anInteractive->Attributes ();
963 // default attributes
964 Quantity_Parameter aRed = 0.0;
965 Quantity_Parameter aGreen = 0.0;
966 Quantity_Parameter aBlue = 0.0;
967 Standard_Real aWidth = 1.0;
968 Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
970 // turn boundaries on/off
971 Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[3]) == 1);
972 aDrawer->SetFaceBoundaryDraw (isBoundaryDraw);
974 // set boundary color
978 aRed = Draw::Atof (argv[4])/255.;
979 aGreen = Draw::Atof (argv[5])/255.;
980 aBlue = Draw::Atof (argv[6])/255.;
986 aWidth = (Standard_Real)Draw::Atof (argv[7]);
989 // select appropriate line type
992 switch (Draw::Atoi (argv[8]))
994 case 1: aLineType = Aspect_TOL_DASH; break;
995 case 2: aLineType = Aspect_TOL_DOT; break;
996 case 3: aLineType = Aspect_TOL_DOTDASH; break;
998 aLineType = Aspect_TOL_SOLID;
1002 Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB);
1004 Handle(Prs3d_LineAspect) aBoundaryAspect =
1005 new Prs3d_LineAspect (aColor, aLineType, aWidth);
1007 aDrawer->SetFaceBoundaryAspect (aBoundaryAspect);
1009 aContext->Redisplay (anInteractive);
1014 //=======================================================================
1015 //function : testDoc
1016 //purpose : Method to test destruction of document
1017 //=======================================================================
1018 static Standard_Integer testDoc (Draw_Interpretor& di,
1019 Standard_Integer argc,
1024 cout<<"Invalid numbers of arguments should be: XTestDoc shape"<<endl;
1027 TopoDS_Shape shape = DBRep::Get(argv[1]);
1031 Handle(XCAFApp_Application) A = XCAFApp_Application::GetApplication();
1033 Handle(TDocStd_Document) aD1 = new TDocStd_Document("MDTV-XCAF");
1036 Handle(V3d_Viewer) vw = ViewerTest_Tool::MakeViewer ("Test viwer");
1037 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(vw);
1038 TPrsStd_AISViewer::New (aD1->Main(),aContext);
1039 // get shape tool for shape verification
1040 Handle(XCAFDoc_ShapeTool) aShapes =
1041 XCAFDoc_DocumentTool::ShapeTool (aD1->Main());
1042 TDF_Label aLab = aShapes->AddShape(shape);
1044 Handle(Geom_Axis2Placement) aPlacement =
1045 new Geom_Axis2Placement (gp::Origin(), gp::DZ(),gp::DX());
1046 Handle(AIS_Trihedron) aTriShape = new AIS_Trihedron (aPlacement);
1048 Handle(TNaming_NamedShape) NS;
1049 Handle(TPrsStd_AISPresentation) prs;
1050 if( aLab.FindAttribute( TNaming_NamedShape::GetID(), NS) ) {
1051 prs = TPrsStd_AISPresentation::Set( NS );
1054 if( aLab.FindAttribute(TPrsStd_AISPresentation::GetID(), prs) )
1058 TPrsStd_AISViewer::Update(aLab);
1059 aContext->Display(aTriShape, Standard_True);
1060 Handle(TDocStd_Owner) owner;
1061 if (aD1->Main().Root().FindAttribute(TDocStd_Owner::GetID(), owner))
1063 Handle_TDocStd_Document empty;
1064 owner->SetDocument(empty);
1073 //=======================================================================
1076 //=======================================================================
1078 void XDEDRAW::Init(Draw_Interpretor& di)
1081 static Standard_Boolean initactor = Standard_False;
1082 if (initactor) return; initactor = Standard_True;
1084 // Load static variables for STEPCAF (ssv; 16.08.2012)
1085 STEPCAFControl_Controller::Init();
1087 // OCAF *** szy: use <pload> command
1089 // DDF::AllCommands(di);
1090 // DNaming::AllCommands(di);
1091 // DDataStd::AllCommands(di);
1092 // DPrsStd::AllCommands(di);
1093 //DFunction::AllCommands(di);
1094 // DDocStd::AllCommands(di);
1096 // ViewerTest::Commands (di); *** szy: use <pload> command
1098 // init XCAF application (if not yet done)
1099 XCAFApp_Application::GetApplication();
1101 //=====================================
1103 //=====================================
1105 Standard_CString g = "XDE general commands";
1107 di.Add ("XNewDoc","DocName \t: Create new DECAF document",
1108 __FILE__, newDoc, g);
1110 di.Add ("XSave","[Doc Path] \t: Save Doc or first document in session",
1111 __FILE__, saveDoc, g);
1113 di.Add ("XOpen","Path Doc \t: Open XDE Document with name Doc from Path",
1114 __FILE__, openDoc, g);
1116 di.Add ("Xdump","Doc [int deep (0/1)] \t: Print information about tree's structure",
1119 di.Add ("XStat","Doc \t: Print statistics of document",
1120 __FILE__, statdoc, g);
1122 di.Add ("XSetPrs","Doc [label1 lavbel2 ...] \t: Set presentation for given label(s) or whole doc",
1123 __FILE__, setPrs, g);
1125 di.Add ("XShow","Doc [label1 lavbel2 ...] \t: Display document (or some labels) in a graphical window",
1128 di.Add ("XWdump","Doc filename.{gif|xwd|bmp} \t: Dump contents of viewer window to XWD, GIF or BMP file",
1131 di.Add ("XAttributeValue", "Doc label #attribute: internal command for browser",
1132 __FILE__, XAttributeValue, g);
1134 di.Add ("XSetViewNameMode", "(1/0) \t: Set/Unset mode of displaying names.",
1135 __FILE__, setviewName, g);
1137 di.Add ("XGetViewNameMode", "\t: Print if mode of displaying names is turn on.",
1138 __FILE__, getviewName, g);
1140 di.Add ("XSetTransparency", "Doc Transparency [label1 label2 ...]\t: Set transparency for given label(s) or whole doc",
1141 __FILE__, XSetTransparency, g);
1143 di.Add ("XShowFaceBoundary",
1144 "Doc Label IsOn [R G B [LineWidth [LineStyle]]]:"
1145 "- turns on/off drawing of face boundaries and defines boundary line style",
1146 __FILE__, XShowFaceBoundary, g);
1147 di.Add ("XTestDoc", "XTestDoc shape", __FILE__, testDoc, g);
1149 // Specialized commands
1150 XDEDRAW_Shapes::InitCommands ( di );
1151 XDEDRAW_Colors::InitCommands ( di );
1152 XDEDRAW_Layers::InitCommands ( di );
1153 XDEDRAW_Props::InitCommands ( di );
1154 XDEDRAW_Common::InitCommands ( di );//moved from EXE
1159 //==============================================================================
1161 //==============================================================================
1162 void XDEDRAW::Factory(Draw_Interpretor& theDI)
1164 XSDRAWIGES::InitSelect();
1165 XSDRAWIGES::InitToBRep(theDI);
1166 XSDRAWIGES::InitFromBRep(theDI);
1168 XSDRAWSTEP::InitCommands(theDI);
1170 SWDRAW::Init(theDI);
1171 XSDRAW::LoadDraw(theDI);
1173 XDEDRAW::Init(theDI);
1176 theDI << "Draw Plugin : All TKXDEDRAW commands are loaded" << "\n";
1180 // Declare entry point PLUGINFACTORY