1 // Created on: 2016-11-22
2 // Created by: Irina KRYLOVA
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <XDEDRAW_Views.hxx>
19 #include <DDocStd.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <Geom_Plane.hxx>
23 #include <TCollection_HAsciiString.hxx>
24 #include <TDF_Tool.hxx>
25 #include <TDF_Label.hxx>
26 #include <TDF_LabelSequence.hxx>
27 #include <TDocStd_Document.hxx>
28 #include <XCAFDoc_ClippingPlaneTool.hxx>
29 #include <XCAFDoc_DimTolTool.hxx>
30 #include <XCAFDoc_DocumentTool.hxx>
31 #include <XCAFDoc_ShapeTool.hxx>
32 #include <XCAFDoc_View.hxx>
33 #include <XCAFDoc_ViewTool.hxx>
34 #include <XCAFView_Object.hxx>
36 //=======================================================================
39 //=======================================================================
40 static Standard_Integer setView(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
43 di << "Use: XSetView Doc shape_label1 ... shape_labelN gdt_label1 ... gdt_labelN\n";
46 Handle(TDocStd_Document) aDoc;
47 DDocStd::GetDocument(argv[1], aDoc);
49 di << argv[1] << " is not a document\n";
52 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
53 Handle(XCAFDoc_DimTolTool) aDimTolTool = XCAFDoc_DocumentTool::DimTolTool(aDoc->Main());
54 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
56 TDF_LabelSequence aShapes, aGDTs;
57 for (Standard_Integer i = 2; i < argc; i++) {
59 TDF_Tool::Label(aDoc->GetData(), argv[i], aLabel);
62 if (aShapeTool->IsShape(aLabel))
63 aShapes.Append(aLabel);
64 else if (aDimTolTool->IsDatum(aLabel) || aDimTolTool->IsDimension(aLabel) || aDimTolTool->IsGeomTolerance(aLabel))
68 if (aShapes.Length() == 0 && aGDTs.Length() == 0)
71 TDF_Label aViewL = aViewTool->AddView();
72 aViewTool->SetView(aShapes, aGDTs, aViewL);
73 TCollection_AsciiString anEntry;
74 TDF_Tool::Entry(aViewL, anEntry);
75 di << anEntry << "\n";
79 //=======================================================================
80 //function : removeView
82 //=======================================================================
83 static Standard_Integer removeView(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
86 di << "Use: XRemoveView Doc View_Label\n";
89 Handle(TDocStd_Document) aDoc;
90 DDocStd::GetDocument(argv[1], aDoc);
92 di << argv[1] << " is not a document\n";
95 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
98 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
101 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
104 aViewTool->RemoveView(aLabel);
109 //=======================================================================
110 //function : setClippingPlanes
112 //=======================================================================
113 static Standard_Integer setClippingPlanes(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
116 di << "Use: XSetClippingPlanes Doc view_label plane_label1 ... plane_labelN";
119 Handle(TDocStd_Document) aDoc;
120 DDocStd::GetDocument(argv[1], aDoc);
122 di << argv[1] << " is not a document\n";
125 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
126 Handle(XCAFDoc_ClippingPlaneTool) aCPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(aDoc->Main());
128 TDF_LabelSequence aCPlanes;
129 for (Standard_Integer i = 3; i < argc; i++) {
131 TDF_Tool::Label(aDoc->GetData(), argv[i], aLabel);
134 if (aCPlaneTool->IsClippingPlane(aLabel))
135 aCPlanes.Append(aLabel);
138 if (aCPlanes.Length() == 0)
142 TDF_Tool::Label(aDoc->GetData(), argv[2], aViewL);
143 aViewTool->SetClippingPlanes(aCPlanes, aViewL);
147 //=======================================================================
150 //=======================================================================
151 static Standard_Integer isView(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
154 di << "Use: XIsView Doc Label\n";
157 Handle(TDocStd_Document) aDoc;
158 DDocStd::GetDocument(argv[1], aDoc);
160 di << argv[1] << " is not a document\n";
163 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
166 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
169 di << "Invalid label\n";
173 if (aViewTool->IsView(aLabel))
181 //=======================================================================
182 //function : getRefShapes
184 //=======================================================================
185 static Standard_Integer getRefShapes(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
188 di << "Use: XGetViewShapes Doc ViewLabel\n";
191 Handle(TDocStd_Document) aDoc;
192 DDocStd::GetDocument(argv[1], aDoc);
194 di << argv[1] << " is not a document\n";
197 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
200 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
201 if (aLabel.IsNull() || !aViewTool->IsView(aLabel))
203 di << "Invalid label\n";
207 TDF_LabelSequence aShapes;
208 aViewTool->GetRefShapeLabel(aLabel, aShapes);
209 for (Standard_Integer i = 1; i <= aShapes.Length(); i++) {
210 TCollection_AsciiString anEntry;
211 TDF_Tool::Entry(aShapes.Value(i), anEntry);
212 di << anEntry << " ";
217 //=======================================================================
218 //function : getRefGDTs
220 //=======================================================================
221 static Standard_Integer getRefGDTs(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
224 di << "Use: XGetViewGDTs Doc ViewLabel\n";
227 Handle(TDocStd_Document) aDoc;
228 DDocStd::GetDocument(argv[1], aDoc);
230 di << argv[1] << " is not a document\n";
233 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
236 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
237 if (aLabel.IsNull() || !aViewTool->IsView(aLabel))
239 di << "Invalid label\n";
243 TDF_LabelSequence aGDTs;
244 aViewTool->GetRefGDTLabel(aLabel, aGDTs);
245 if (aGDTs.Length() == 0) {
246 di << "No GDTs in the given View\n";
248 for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
249 TCollection_AsciiString anEntry;
250 TDF_Tool::Entry(aGDTs.Value(i), anEntry);
251 di << anEntry << " ";
256 //=======================================================================
257 //function : getRefClippingPlanes
259 //=======================================================================
260 static Standard_Integer getRefClippingPlanes(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
263 di << "Use: XGetViewClippingPlanes Doc ViewLabel\n";
266 Handle(TDocStd_Document) aDoc;
267 DDocStd::GetDocument(argv[1], aDoc);
269 di << argv[1] << " is not a document\n";
272 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
275 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
276 if (aLabel.IsNull() || !aViewTool->IsView(aLabel))
278 di << "Invalid label\n";
282 TDF_LabelSequence aCPlanes;
283 aViewTool->GetRefClippingPlaneLabel(aLabel, aCPlanes);
284 if (aCPlanes.Length() == 0) {
285 di << "No Clipping Planes in the given View\n";
287 for (Standard_Integer i = 1; i <= aCPlanes.Length(); i++) {
288 TCollection_AsciiString anEntry;
289 TDF_Tool::Entry(aCPlanes.Value(i), anEntry);
290 di << anEntry << " ";
295 //=======================================================================
298 //=======================================================================
299 static Standard_Integer setName(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
302 di << "Use: XSetViewName Doc ViewLabel name\n";
305 Handle(TDocStd_Document) aDoc;
306 DDocStd::GetDocument(argv[1], aDoc);
308 di << argv[1] << " is not a document\n";
311 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
314 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
317 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
320 Handle(XCAFDoc_View) aView;
321 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
323 Handle(XCAFView_Object) anObj = aView->GetObject();
324 anObj->SetName(new TCollection_HAsciiString(argv[3]));
325 aView->SetObject(anObj);
330 //=======================================================================
333 //=======================================================================
334 static Standard_Integer getName(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
337 di << "Use: XGetViewName Doc View_Label\n";
340 Handle(TDocStd_Document) aDoc;
341 DDocStd::GetDocument(argv[1], aDoc);
343 di << argv[1] << " is not a document\n";
346 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
349 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
352 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
355 Handle(XCAFDoc_View) aView;
356 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
358 di << aView->GetObject()->Name()->String();
363 //=======================================================================
366 //=======================================================================
367 static Standard_Integer setType(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
370 di << "Use: XSetViewType Doc ViewLabel type (central/parallel/no_camera)\n";
373 Handle(TDocStd_Document) aDoc;
374 DDocStd::GetDocument(argv[1], aDoc);
376 di << argv[1] << " is not a document\n";
379 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
382 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
385 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
388 Handle(XCAFDoc_View) aView;
389 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
391 Handle(XCAFView_Object) anObj = aView->GetObject();
392 XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera;
393 if (argv[3][0] == 'c')
394 aType = XCAFView_ProjectionType_Central;
395 else if (argv[3][0] == 'p')
396 aType = XCAFView_ProjectionType_Parallel;
397 anObj->SetType(aType);
398 aView->SetObject(anObj);
403 //=======================================================================
406 //=======================================================================
407 static Standard_Integer getType(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
410 di << "Use: XGetViewType Doc View_Label\n";
413 Handle(TDocStd_Document) aDoc;
414 DDocStd::GetDocument(argv[1], aDoc);
416 di << argv[1] << " is not a document\n";
419 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
422 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
425 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
428 Handle(XCAFDoc_View) aView;
429 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
431 XCAFView_ProjectionType aType = aView->GetObject()->Type();
433 case XCAFView_ProjectionType_NoCamera:
436 case XCAFView_ProjectionType_Central:
439 case XCAFView_ProjectionType_Parallel:
447 //=======================================================================
448 //function : setProjectionPont
450 //=======================================================================
451 static Standard_Integer setProjectionPoint(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
454 di << "Use: XSetViewProjectionPoint Doc ViewLabel x y z\n";
457 Handle(TDocStd_Document) aDoc;
458 DDocStd::GetDocument(argv[1], aDoc);
460 di << argv[1] << " is not a document\n";
463 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
466 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
469 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
472 Handle(XCAFDoc_View) aView;
473 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
475 Handle(XCAFView_Object) anObj = aView->GetObject();
476 anObj->SetProjectionPoint(gp_Pnt(Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5])));
477 aView->SetObject(anObj);
482 //=======================================================================
483 //function : getProjectionPoint
485 //=======================================================================
486 static Standard_Integer getProjectionPoint(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
489 di << "Use: XGetViewProjectionPoint Doc ViewLabel\n";
492 Handle(TDocStd_Document) aDoc;
493 DDocStd::GetDocument(argv[1], aDoc);
495 di << argv[1] << " is not a document\n";
498 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
501 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
504 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
507 Handle(XCAFDoc_View) aView;
508 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
510 gp_Pnt aPnt = aView->GetObject()->ProjectionPoint();
511 di << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z();
516 //=======================================================================
517 //function : setViewDir
519 //=======================================================================
520 static Standard_Integer setViewDir(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
523 di << "Use: XSetViewDir Doc ViewLabel x y z\n";
526 Handle(TDocStd_Document) aDoc;
527 DDocStd::GetDocument(argv[1], aDoc);
529 di << argv[1] << " is not a document\n";
532 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
535 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
538 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
541 Handle(XCAFDoc_View) aView;
542 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
544 Handle(XCAFView_Object) anObj = aView->GetObject();
545 anObj->SetViewDirection(gp_Dir(Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5])));
546 aView->SetObject(anObj);
551 //=======================================================================
552 //function : getViewDir
554 //=======================================================================
555 static Standard_Integer getViewDir(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
558 di << "Use: XGetViewDir Doc ViewLabel\n";
561 Handle(TDocStd_Document) aDoc;
562 DDocStd::GetDocument(argv[1], aDoc);
564 di << argv[1] << " is not a document\n";
567 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
570 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
573 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
576 Handle(XCAFDoc_View) aView;
577 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
579 gp_Dir aDir = aView->GetObject()->ViewDirection();
580 di << aDir.X() << " " << aDir.Y() << " " << aDir.Z();
585 //=======================================================================
586 //function : setUpDir
588 //=======================================================================
589 static Standard_Integer setUpDir(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
592 di << "Use: XSetViewUpDir Doc ViewLabel x y z\n";
595 Handle(TDocStd_Document) aDoc;
596 DDocStd::GetDocument(argv[1], aDoc);
598 di << argv[1] << " is not a document\n";
601 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
604 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
607 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
610 Handle(XCAFDoc_View) aView;
611 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
613 Handle(XCAFView_Object) anObj = aView->GetObject();
614 anObj->SetUpDirection(gp_Dir(Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5])));
615 aView->SetObject(anObj);
620 //=======================================================================
621 //function : getUpDir
623 //=======================================================================
624 static Standard_Integer getUpDir(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
627 di << "Use: XGetViewUpDir Doc ViewLabel\n";
630 Handle(TDocStd_Document) aDoc;
631 DDocStd::GetDocument(argv[1], aDoc);
633 di << argv[1] << " is not a document\n";
636 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
639 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
642 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
645 Handle(XCAFDoc_View) aView;
646 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
648 gp_Dir aDir = aView->GetObject()->UpDirection();
649 di << aDir.X() << " " << aDir.Y() << " " << aDir.Z();
654 //=======================================================================
655 //function : setZoomFactor
657 //=======================================================================
658 static Standard_Integer setZoomFactor(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
661 di << "Use: XSetViewZoom Doc View_Label value\n";
664 Handle(TDocStd_Document) aDoc;
665 DDocStd::GetDocument(argv[1], aDoc);
667 di << argv[1] << " is not a document\n";
670 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
673 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
676 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
679 Handle(XCAFDoc_View) aView;
680 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
682 Handle(XCAFView_Object) anObj = aView->GetObject();
683 anObj->SetZoomFactor(Draw::Atof(argv[3]));
684 aView->SetObject(anObj);
689 //=======================================================================
690 //function : getZoomFactor
692 //=======================================================================
693 static Standard_Integer getZoomFactor(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
696 di << "Use: XGetViewZoom Doc View_Label\n";
699 Handle(TDocStd_Document) aDoc;
700 DDocStd::GetDocument(argv[1], aDoc);
702 di << argv[1] << " is not a document\n";
705 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
708 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
711 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
714 Handle(XCAFDoc_View) aView;
715 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
717 di << aView->GetObject()->ZoomFactor();
722 //=======================================================================
723 //function : setWindowSize
725 //=======================================================================
726 static Standard_Integer setWindowSize(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
729 di << "Use: XSetViewWindowSize Doc ViewLabel width height\n";
732 Handle(TDocStd_Document) aDoc;
733 DDocStd::GetDocument(argv[1], aDoc);
735 di << argv[1] << " is not a document\n";
738 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
741 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
744 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
747 Handle(XCAFDoc_View) aView;
748 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
750 Handle(XCAFView_Object) anObj = aView->GetObject();
751 anObj->SetWindowHorizontalSize(Draw::Atof(argv[3]));
752 anObj->SetWindowVerticalSize(Draw::Atof(argv[4]));
753 aView->SetObject(anObj);
758 //=======================================================================
759 //function : getWindowSize
761 //=======================================================================
762 static Standard_Integer getWindowSize(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
765 di << "Use: XSetViewWindowSize Doc Dim_Label\n";
768 Handle(TDocStd_Document) aDoc;
769 DDocStd::GetDocument(argv[1], aDoc);
771 di << argv[1] << " is not a document\n";
774 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
777 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
780 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
783 Handle(XCAFDoc_View) aView;
784 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
786 di << "width " << aView->GetObject()->WindowHorizontalSize();
787 di << " height " << aView->GetObject()->WindowVerticalSize();
792 //=======================================================================
793 //function : setFrontPlaneDistance
795 //=======================================================================
796 static Standard_Integer setFrontPlaneDistance(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
799 di << "Use: XSetViewFrontPlaneDistance Doc View_Label value\n";
802 Handle(TDocStd_Document) aDoc;
803 DDocStd::GetDocument(argv[1], aDoc);
805 di << argv[1] << " is not a document\n";
808 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
811 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
814 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
817 Handle(XCAFDoc_View) aView;
818 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
820 Handle(XCAFView_Object) anObj = aView->GetObject();
821 anObj->SetFrontPlaneDistance(Draw::Atof(argv[3]));
822 aView->SetObject(anObj);
827 //=======================================================================
828 //function : unsetFrontPlaneDistance
830 //=======================================================================
831 static Standard_Integer unsetFrontPlaneDistance(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
834 di << "Use: XUnsetViewFrontPlaneDistance Doc View_Label\n";
837 Handle(TDocStd_Document) aDoc;
838 DDocStd::GetDocument(argv[1], aDoc);
840 di << argv[1] << " is not a document\n";
843 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
846 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
849 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
852 Handle(XCAFDoc_View) aView;
853 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
855 Handle(XCAFView_Object) anObj = aView->GetObject();
856 anObj->UnsetFrontPlaneClipping();
857 aView->SetObject(anObj);
862 //=======================================================================
863 //function : getFrontPlaneDistance
865 //=======================================================================
866 static Standard_Integer getFrontPlaneDistance(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
869 di << "Use: XGetViewFrontPlaneDistance Doc View_Label\n";
872 Handle(TDocStd_Document) aDoc;
873 DDocStd::GetDocument(argv[1], aDoc);
875 di << argv[1] << " is not a document\n";
878 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
881 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
884 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
887 Handle(XCAFDoc_View) aView;
888 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
890 if (aView->GetObject()->HasFrontPlaneClipping())
891 di << aView->GetObject()->FrontPlaneDistance();
893 di << "View has not front plane clipping\n";
898 //=======================================================================
899 //function : setBackPlaneDistance
901 //=======================================================================
902 static Standard_Integer setBackPlaneDistance(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
905 di << "Use: XSetViewBackPlaneDistance Doc View_Label value\n";
908 Handle(TDocStd_Document) aDoc;
909 DDocStd::GetDocument(argv[1], aDoc);
911 di << argv[1] << " is not a document\n";
914 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
917 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
920 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
923 Handle(XCAFDoc_View) aView;
924 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
926 Handle(XCAFView_Object) anObj = aView->GetObject();
927 anObj->SetBackPlaneDistance(Draw::Atof(argv[3]));
928 aView->SetObject(anObj);
933 //=======================================================================
934 //function : unsetBackPlaneDistance
936 //=======================================================================
937 static Standard_Integer unsetBackPlaneDistance(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
940 di << "Use: XUnsetViewBackPlaneDistance Doc View_Label\n";
943 Handle(TDocStd_Document) aDoc;
944 DDocStd::GetDocument(argv[1], aDoc);
946 di << argv[1] << " is not a document\n";
949 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
952 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
955 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
958 Handle(XCAFDoc_View) aView;
959 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
961 Handle(XCAFView_Object) anObj = aView->GetObject();
962 anObj->UnsetBackPlaneClipping();
963 aView->SetObject(anObj);
968 //=======================================================================
969 //function : getBackPlaneDistance
971 //=======================================================================
972 static Standard_Integer getBackPlaneDistance(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
975 di << "Use: XGetViewFrontPlaneDistance Doc View_Label\n";
978 Handle(TDocStd_Document) aDoc;
979 DDocStd::GetDocument(argv[1], aDoc);
981 di << argv[1] << " is not a document\n";
984 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
987 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
990 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
993 Handle(XCAFDoc_View) aView;
994 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
996 if (aView->GetObject()->HasBackPlaneClipping())
997 di << aView->GetObject()->BackPlaneDistance();
999 di << "View has not back plane clipping\n";
1004 //=======================================================================
1005 //function : setViewVolumeSidesClipping
1007 //=======================================================================
1008 static Standard_Integer setViewVolumeSidesClipping(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1011 di << "Use: XSetViewVolumeSidesClipping Doc View_Label value\n";
1014 Handle(TDocStd_Document) aDoc;
1015 DDocStd::GetDocument(argv[1], aDoc);
1016 if (aDoc.IsNull()) {
1017 di << argv[1] << " is not a document\n";
1020 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
1023 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
1024 if (aLabel.IsNull())
1026 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
1029 Handle(XCAFDoc_View) aView;
1030 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
1032 Handle(XCAFView_Object) anObj = aView->GetObject();
1033 anObj->SetViewVolumeSidesClipping((Draw::Atoi(argv[3])) == 1);
1034 aView->SetObject(anObj);
1039 //=======================================================================
1040 //function : getViewVolumeSidesClipping
1042 //=======================================================================
1043 static Standard_Integer getViewVolumeSidesClipping(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1046 di << "Use: XGetViewVolumeSidesClipping Doc View_Label\n";
1049 Handle(TDocStd_Document) aDoc;
1050 DDocStd::GetDocument(argv[1], aDoc);
1051 if (aDoc.IsNull()) {
1052 di << argv[1] << " is not a document\n";
1055 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
1058 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
1059 if (aLabel.IsNull())
1061 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
1064 Handle(XCAFDoc_View) aView;
1065 if (aLabel.FindAttribute(XCAFDoc_View::GetID(), aView))
1067 di << aView->GetObject()->HasViewVolumeSidesClipping();
1072 //=======================================================================
1075 //=======================================================================
1076 static Standard_Integer dump(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1079 di << "Use: XDumpView Doc View_Label\n";
1082 Handle(TDocStd_Document) aDoc;
1083 DDocStd::GetDocument(argv[1], aDoc);
1084 if (aDoc.IsNull()) {
1085 di << argv[1] << " is not a document\n";
1088 Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(aDoc->Main());
1091 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
1092 Handle(XCAFDoc_View) aView;
1093 if (aLabel.IsNull() || !(aLabel.FindAttribute(XCAFDoc_View::GetID(), aView)))
1095 di << "View " << argv[2] << " is absent in " << argv[1] << "\n";
1099 TDF_LabelSequence aShapes;
1100 aViewTool->GetRefShapeLabel(aLabel, aShapes);
1101 di << "Reference shapes: ";
1102 for (Standard_Integer i = 1; i <= aShapes.Length(); i++) {
1103 TCollection_AsciiString anEntry;
1104 TDF_Tool::Entry(aShapes.Value(i), anEntry);
1105 di << anEntry << " ";
1109 TDF_LabelSequence aGDTs;
1110 aViewTool->GetRefGDTLabel(aLabel, aGDTs);
1111 di << "Reference GD&Ts: ";
1112 for (Standard_Integer i = 1; i <= aGDTs.Length(); i++) {
1113 TCollection_AsciiString anEntry;
1114 TDF_Tool::Entry(aGDTs.Value(i), anEntry);
1115 di << anEntry << " ";
1119 TDF_LabelSequence aCPlanes;
1120 aViewTool->GetRefClippingPlaneLabel(aLabel, aCPlanes);
1121 di << "Reference Clipping Planes: ";
1122 for (Standard_Integer i = 1; i <= aCPlanes.Length(); i++) {
1123 TCollection_AsciiString anEntry;
1124 TDF_Tool::Entry(aCPlanes.Value(i), anEntry);
1125 di << anEntry << " ";
1129 di << "Name: " << aView->GetObject()->Name()->String() << "\n";
1131 XCAFView_ProjectionType aType = aView->GetObject()->Type();
1133 case XCAFView_ProjectionType_NoCamera:
1134 di << "Type: no_camera\n";
1136 case XCAFView_ProjectionType_Central:
1137 di << "Type: central\n";
1139 case XCAFView_ProjectionType_Parallel:
1140 di << "Type: parallel\n";
1144 gp_Pnt aPnt = aView->GetObject()->ProjectionPoint();
1145 di << "Projection point: "<< aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z() << "\n";
1147 gp_Dir aDir = aView->GetObject()->ViewDirection();
1148 di << "View Direction: " << aDir.X() << " " << aDir.Y() << " " << aDir.Z() << "\n";
1150 aDir = aView->GetObject()->UpDirection();
1151 di << "Up Direction: " << aDir.X() << " " << aDir.Y() << " " << aDir.Z() << "\n";
1153 di << "Zoom factor: " << aView->GetObject()->ZoomFactor() << "\n";
1155 di << "Window Size: width " << aView->GetObject()->WindowHorizontalSize() << ", " << " height " << aView->GetObject()->WindowVerticalSize() << "\n";
1157 if (aView->GetObject()->HasFrontPlaneClipping())
1158 di << "Front Plane Distance: " << aView->GetObject()->FrontPlaneDistance() << "\n";
1160 di << "No Front Plane\n";
1162 if (aView->GetObject()->HasFrontPlaneClipping())
1163 di << "Front Back Distance: " << aView->GetObject()->BackPlaneDistance() << "\n";
1165 di << "No Back Plane\n";
1167 di << "View VolumeSized Clipping: " << aView->GetObject()->HasViewVolumeSidesClipping() << "\n";
1172 //=======================================================================
1173 //function : addClippingPlane
1175 //=======================================================================
1176 static Standard_Integer addClippingPlane(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1179 di << "Use: XAddClippingPlane Doc plane name capping[0/1]";
1182 Handle(TDocStd_Document) aDoc;
1183 DDocStd::GetDocument(argv[1], aDoc);
1184 if (aDoc.IsNull()) {
1185 di << argv[1] << " is not a document\n";
1188 Handle(XCAFDoc_ClippingPlaneTool) aCPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(aDoc->Main());
1190 Handle(Geom_Plane) aSurf = Handle(Geom_Plane)::DownCast(DrawTrSurf::GetSurface(argv[2]));
1191 if (aSurf.IsNull()) {
1192 std::cout << argv[2] << " is not a plane" << std::endl;
1195 aPlane = aSurf->Pln();
1196 Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(argv[3]);
1197 Standard_Boolean aCapping = (argv[4][0] == '1');
1199 TDF_Label aCPlaneL = aCPlaneTool->AddClippingPlane(aPlane, aName, aCapping);
1200 TCollection_AsciiString anEntry;
1201 TDF_Tool::Entry(aCPlaneL, anEntry);
1202 di << anEntry << "\n";
1206 //=======================================================================
1207 //function : getClippingPlane
1209 //=======================================================================
1210 static Standard_Integer getClippingPlane(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1213 di << "Use: XGetClippingPlane Doc ClippingPlane_Label\n";
1216 Handle(TDocStd_Document) aDoc;
1217 DDocStd::GetDocument(argv[1], aDoc);
1218 if (aDoc.IsNull()) {
1219 di << argv[1] << " is not a document\n";
1222 Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(aDoc->Main());
1225 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
1226 if (aLabel.IsNull())
1228 di << "ClippingPlane " << argv[2] << " is absent in " << argv[1] << "\n";
1232 Handle(TCollection_HAsciiString) aName;
1233 Standard_Boolean aCapping;
1234 aClippingPlaneTool->GetClippingPlane(aLabel, aPlane, aName, aCapping);
1235 Handle(Geom_Plane) aCPlane = new Geom_Plane(aPlane);
1236 DrawTrSurf::Set(aName->ToCString(), aCPlane);
1237 di << aName->ToCString();
1241 //=======================================================================
1242 //function : removeClippingPlane
1244 //=======================================================================
1245 static Standard_Integer removeClippingPlane(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1248 di << "Use: XRemoveClippingPlane Doc ClippingPlane_Label\n";
1251 Handle(TDocStd_Document) aDoc;
1252 DDocStd::GetDocument(argv[1], aDoc);
1253 if (aDoc.IsNull()) {
1254 di << argv[1] << " is not a document\n";
1257 Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(aDoc->Main());
1260 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
1261 if (aLabel.IsNull())
1263 di << "ClippingPlane " << argv[2] << " is absent in " << argv[1] << "\n";
1266 Standard_Boolean isRemoved = aClippingPlaneTool->RemoveClippingPlane(aLabel);
1270 di << "clipping plane is not free, not removed\n";
1274 //=======================================================================
1275 //function : getClippingPlaneCapping
1277 //=======================================================================
1278 static Standard_Integer getClippingPlaneCapping(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1281 di << "Use: XGetClippingPlaneCapping Doc ClippingPlane_Label\n";
1284 Handle(TDocStd_Document) aDoc;
1285 DDocStd::GetDocument(argv[1], aDoc);
1286 if (aDoc.IsNull()) {
1287 di << argv[1] << " is not a document\n";
1290 Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(aDoc->Main());
1293 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
1294 if (aLabel.IsNull())
1296 di << "ClippingPlane " << argv[2] << " is absent in " << argv[1] << "\n";
1299 di << aClippingPlaneTool->GetCapping(aLabel);
1303 //=======================================================================
1304 //function : InitCommands
1306 //=======================================================================
1308 void XDEDRAW_Views::InitCommands(Draw_Interpretor& di)
1310 static Standard_Boolean initactor = Standard_False;
1315 initactor = Standard_True;
1317 Standard_CString g = "XDE Views commands";
1319 di.Add("XSetView", "XSetView Doc shape_label1 ... shape_labelN gdt_label1 ... gdt_labelN",
1320 __FILE__, setView, g);
1322 di.Add("XRemoveView", "XRemoveView Doc ViewLabel",
1323 __FILE__, removeView, g);
1325 di.Add("XSetClippingPlanes", "XSetView Doc view_plane plane_label1 ... plane_labelN",
1326 __FILE__, setClippingPlanes, g);
1328 di.Add("XIsView", "XIsView Doc Label",
1329 __FILE__, isView, g);
1331 di.Add("XGetViewShapes", "XGetViewShapes Doc ViewLabel" "Return labels of reference shapes",
1332 __FILE__, getRefShapes, g);
1334 di.Add("XGetViewGDTs", "XGetViewGDTs Doc ViewLabel" "Return labels of reference GDTs",
1335 __FILE__, getRefGDTs, g);
1337 di.Add("XGetViewClippingPlanes", "XGetViewClippingPlanes Doc ViewLabel" "Return labels of reference Clipping Planes",
1338 __FILE__, getRefClippingPlanes, g);
1340 di.Add("XSetViewName", "XSetViewName Doc ViewLabel name",
1341 __FILE__, setName, g);
1343 di.Add("XGetViewName", "XGetViewName Doc ViewLabel",
1344 __FILE__, getName, g);
1346 di.Add("XSetViewType", "XSetViewType Doc ViewLabel type (central/parallel/no_camera)",
1347 __FILE__, setType, g);
1349 di.Add("XGetViewType", "XGetViewType Doc ViewLabel",
1350 __FILE__, getType, g);
1352 di.Add("XSetViewProjectionPoint", "XSetViewProjectionPoint Doc ViewLabel x y z",
1353 __FILE__, setProjectionPoint, g);
1355 di.Add("XGetViewProjectionPoint", "XGetViewProjectionPoint Doc ViewLabel",
1356 __FILE__, getProjectionPoint, g);
1358 di.Add("XSetViewDir", "XSetViewDir Doc ViewLabel x y z",
1359 __FILE__, setViewDir, g);
1361 di.Add("XGetViewDir", "XGetViewDir Doc ViewLabel",
1362 __FILE__, getViewDir, g);
1364 di.Add("XSetViewUpDir", "XSetViewUpDir Doc ViewLabel x y z",
1365 __FILE__, setUpDir, g);
1367 di.Add("XGetViewUpDir", "XGetViewUpDir Doc ViewLabel",
1368 __FILE__, getUpDir, g);
1370 di.Add("XSetViewZoom", "XSetViewZoom Doc ViewLabel zoom_factor",
1371 __FILE__, setZoomFactor, g);
1373 di.Add("XGetViewZoom", "XGetViewZoom Doc ViewLabel",
1374 __FILE__, getZoomFactor, g);
1376 di.Add("XSetViewWindowSize", "XSetViewWindowSize Doc ViewLabel width height",
1377 __FILE__, setWindowSize, g);
1379 di.Add("XGetViewWindowSize", "XGetViewWindowSize Doc ViewLabel",
1380 __FILE__, getWindowSize, g);
1382 di.Add("XSetViewFrontPlaneDistance", "XSetViewFrontPlaneDistance Doc ViewLabel distance",
1383 __FILE__, setFrontPlaneDistance, g);
1385 di.Add("XUnsetViewFrontPlaneDistance", "XSetViewFrontPlaneDistance Doc ViewLabel",
1386 __FILE__, unsetFrontPlaneDistance, g);
1388 di.Add("XGetViewFrontPlaneDistance", "XGetViewFrontPlaneDistance Doc ViewLabel",
1389 __FILE__, getFrontPlaneDistance, g);
1391 di.Add("XSetViewBackPlaneDistance", "XSetViewBackPlaneDistance Doc ViewLabel distance",
1392 __FILE__, setBackPlaneDistance, g);
1394 di.Add("XUnsetViewBackPlaneDistance", "XUnsetViewBackPlaneDistance Doc ViewLabel",
1395 __FILE__, unsetBackPlaneDistance, g);
1397 di.Add("XGetViewBackPlaneDistance", "XGetViewBackPlaneDistance Doc ViewLabel",
1398 __FILE__, getBackPlaneDistance, g);
1400 di.Add("XSetViewVolumeSidesClipping", "XSetViewVolumeSidesClipping Doc ViewLabel value(0 - unset, 1- set)",
1401 __FILE__, setViewVolumeSidesClipping, g);
1403 di.Add("XGetViewVolumeSidesClipping", "XGetViewVolumeSidesClipping Doc ViewLabel",
1404 __FILE__, getViewVolumeSidesClipping, g);
1406 di.Add("XDumpView", "XDumpView Doc ViewLabel",
1409 di.Add("XAddClippingPlane", "XAddClippingPlane Doc plane name capping[0/1]",
1410 __FILE__, addClippingPlane, g);
1412 di.Add("XGetClippingPlaneCapping", "XGetClippingPlaneCapping Doc ClippingPlane_Label",
1413 __FILE__, getClippingPlaneCapping, g);
1415 di.Add("XGetClippingPlane", "XGetClippingPlane Doc ClippingPlane_Label",
1416 __FILE__, getClippingPlane, g);
1418 di.Add("XRemoveClippingPlane", "XRemoveClippingPlane Doc ClippingPlane_Label",
1419 __FILE__, removeClippingPlane, g);