1 // Created on: 1998-10-07
2 // Created by: Denis PASCAL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <DPrsStd.hxx>
19 #include <Draw_Appli.hxx>
20 #include <Draw_Interpretor.hxx>
21 #include <Draw_ColorKind.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TDocStd_Document.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDF_Data.hxx>
27 #include <DDocStd.hxx>
28 #include <ViewerTest.hxx>
31 #include <V3d_View.hxx>
36 #include <TPrsStd_AISPresentation.hxx>
37 #include <TPrsStd_AISViewer.hxx>
38 #include <ViewerTest.hxx>
39 #include <AIS_InteractiveContext.hxx>
40 #include <AIS_InteractiveObject.hxx>
41 #include <AIS_Drawer.hxx>
42 #include <ViewerTest.hxx>
43 #include <V3d_View.hxx>
44 #include <TCollection_ExtendedString.hxx>
45 #include <Quantity_NameOfColor.hxx>
46 #include <Graphic3d_NameOfMaterial.hxx>
48 #include <TDataXtd_Axis.hxx>
49 #include <TDataXtd_Constraint.hxx>
50 #include <TDataXtd_Geometry.hxx>
51 #include <TNaming_NamedShape.hxx>
52 #include <TDataXtd_Plane.hxx>
53 #include <TDataXtd_Point.hxx>
54 #include <Standard_PCharacter.hxx>
56 //#include <TSketchStd_Geometry.hxx>
57 //#include <TSketchStd_Edge.hxx>
59 //=======================================================================
60 //function : DPrsStd_AISDisplay
61 //purpose : DDisplay (DOC,entry, not_update)
62 //=======================================================================
64 static Standard_Integer DPrsStd_AISDisplay (Draw_Interpretor&,
69 Handle(TDocStd_Document) D;
70 if (!DDocStd::GetDocument(arg[1],D)) return 1;
72 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
73 Handle(TPrsStd_AISPresentation) prs;
74 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
76 prs->Display(Standard_True);
77 TPrsStd_AISViewer::Update(L);
82 TPrsStd_AISViewer::Update(L);
87 //=======================================================================
88 //function : DPrsStd_AISRemove
89 //purpose : AISRemove (DOC,entry)
90 //=======================================================================
92 static Standard_Integer DPrsStd_AISRemove (Draw_Interpretor& di,
97 Handle(TDocStd_Document) D;
98 if (!DDocStd::GetDocument(arg[1],D)) return 1;
100 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
101 Handle(TPrsStd_AISPresentation) P;
102 if(!L.FindAttribute(TPrsStd_AISPresentation::GetID(), P)) return 1;
103 P->Erase(Standard_True);
104 TPrsStd_AISViewer::Update(L);
107 di << "DPrsStd_AISRedisplay : Error" << "\n";
112 //=======================================================================
113 //function : DPrsStd_AISErase
114 //purpose : AISErase (DOC,entry)
115 //=======================================================================
117 static Standard_Integer DPrsStd_AISErase (Draw_Interpretor& di,
122 Handle(TDocStd_Document) D;
123 if (!DDocStd::GetDocument(arg[1],D)) return 1;
125 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
126 Handle(TPrsStd_AISPresentation) prs;
127 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
129 TPrsStd_AISViewer::Update(L);
132 di << "DPrsStd_AISErase : Error" << "\n";
136 //=======================================================================
137 //function : DPrsStd_AISUpdate
138 //purpose : AISUpdate (DOC,entry)
139 //=======================================================================
141 static Standard_Integer DPrsStd_AISUpdate (Draw_Interpretor& di,
146 Handle(TDocStd_Document) D;
147 if (!DDocStd::GetDocument(arg[1],D)) return 1;
149 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
150 Handle(TPrsStd_AISPresentation) prs;
151 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
153 TPrsStd_AISViewer::Update(L);
156 di << "DPrsStd_AISUpdate : Error" << "\n";
161 //=======================================================================
162 //function : DPrsStd_AISSet
163 //purpose : AISSet (DOC,entry, id)
164 //=======================================================================
166 static Standard_Integer DPrsStd_AISSet (Draw_Interpretor& di,
171 Handle(TDocStd_Document) D;
172 if (!DDocStd::GetDocument(arg[1],D)) return 1;
174 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
176 TCollection_ExtendedString str = arg[3];
178 cout << "Inputed parameter > " << str << endl;
180 if ( str == "A" ) //axis
181 guid = TDataXtd_Axis::GetID(); //"2a96b601-ec8b-11d0-bee7-080009dc3333"
182 else if( str == "C") //constraint
183 guid = TDataXtd_Constraint::GetID(); //"2a96b602-ec8b-11d0-bee7-080009dc3333"
184 else if( str == "NS" ) //namedshape
185 guid = TNaming_NamedShape::GetID(); //"c4ef4200-568f-11d1-8940-080009dc3333"
186 else if( str == "G" ) //geometry
187 guid = TDataXtd_Geometry::GetID(); //"2a96b604-ec8b-11d0-bee7-080009dc3333"
188 else if( str == "PL" ) //plane
189 guid = TDataXtd_Plane::GetID(); //"2a96b60c-ec8b-11d0-bee7-080009dc3333"
190 else if( str == "PT" ) //point
191 guid = TDataXtd_Point::GetID(); //"2a96b60d-ec8b-11d0-bee7-080009dc3333"
192 // else if( str == "SG" ) //TSketch_Geometry
193 // guid = TSketchStd_Geometry::GetID(); //"b3aac909-5b78-11d1-8940-080009dc3333"
194 // else if( str == "E" ) //TSketch_Edge
195 // guid = TSketchStd_Edge::GetID(); //"b3aac90a-5b78-11d1-8940-080009dc3333"
197 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, guid);
199 cout << "Driver GUID = ";
200 prs->GetDriverGUID().ShallowDump(cout);
203 Standard_Character resS[37];
204 Standard_PCharacter presS;
206 guid.ToCString(presS);
210 di << "DPrsStd_AISSet : Error" << "\n";
214 //=======================================================================
215 //function : DPrsStd_AISDriver
216 //purpose : AISDriver (DOC,entry, [ID])
217 //=======================================================================
219 static Standard_Integer DPrsStd_AISDriver (Draw_Interpretor& di,
224 Handle(TDocStd_Document) D;
225 if (!DDocStd::GetDocument(arg[1],D)) return 1;
227 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
230 Handle(TPrsStd_AISPresentation) prs;
231 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
233 guid = prs->GetDriverGUID();
234 Standard_Character str[37];
235 Standard_PCharacter pstr;
237 guid.ToCString( pstr );
242 TCollection_ExtendedString str = arg[3];
244 cout << "Inputed parameter > " << str << endl;
246 if ( str == "A" ) //axis
247 guid = TDataXtd_Axis::GetID(); //"2a96b601-ec8b-11d0-bee7-080009dc3333"
248 else if( str == "C") //constraint
249 guid = TDataXtd_Constraint::GetID(); //"2a96b602-ec8b-11d0-bee7-080009dc3333"
250 else if( str == "NS" ) //namedshape
251 guid = TNaming_NamedShape::GetID(); //"c4ef4200-568f-11d1-8940-080009dc3333"
252 else if( str == "G" ) //geometry
253 guid = TDataXtd_Geometry::GetID(); //"2a96b604-ec8b-11d0-bee7-080009dc3333"
254 else if( str == "PL" ) //plane
255 guid = TDataXtd_Plane::GetID(); //"2a96b60c-ec8b-11d0-bee7-080009dc3333"
256 else if( str == "PT" ) //point
257 guid = TDataXtd_Point::GetID(); //"2a96b60d-ec8b-11d0-bee7-080009dc3333"
258 // else if( str == "SG" ) //TSketch_Geometry
259 // guid = TSketchStd_Geometry::GetID(); //"b3aac909-5b78-11d1-8940-080009dc3333"
260 // else if( str == "E" ) //TSketch_Edge
261 // guid = TSketchStd_Edge::GetID(); //"b3aac90a-5b78-11d1-8940-080009dc3333"
263 prs->SetDriverGUID(guid);
264 Standard_Character resS[37];
265 Standard_PCharacter presS;
266 //modified by NIZNHY-PKV Tue Apr 22 16:15:02 2008f
268 //modified by NIZNHY-PKV Tue Apr 22 16:15:05 2008t
269 guid.ToCString( presS );
275 di << "DPrsStd_AISDriver : Error" << "\n";
279 //=======================================================================
280 //function : DPrsStd_AISUnset
281 //purpose : AISUnset (DOC,entry)
282 //=======================================================================
284 static Standard_Integer DPrsStd_AISUnset (Draw_Interpretor& di,
289 Handle(TDocStd_Document) D;
290 if (!DDocStd::GetDocument(arg[1],D)) return 1;
292 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
293 TPrsStd_AISPresentation::Unset(L);
294 TPrsStd_AISViewer::Update(L);
297 di << "DPrsStd_AISDriver : Error" << "\n";
302 //=======================================================================
303 //function : DPrsStd_AISTransparency
304 //purpose : AISTransparency (DOC,entry,[real])
305 //=======================================================================
307 static Standard_Integer DPrsStd_AISTransparency (Draw_Interpretor& di,
312 Handle(TDocStd_Document) D;
313 if (!DDocStd::GetDocument(arg[1],D)) return 1;
315 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
317 Handle(TPrsStd_AISViewer) viewer;
318 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
320 Handle(TPrsStd_AISPresentation) prs;
321 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
323 prs->SetTransparency(Draw::Atof(arg[3]));
324 TPrsStd_AISViewer::Update(L);
327 if (prs->HasOwnTransparency()){
328 di << "Transparency = " << prs->Transparency() << "\n";
329 di<<prs->Transparency();
332 di << "DPrsStd_AISTransparency: Warning : Transparency wasn't set" << "\n";
339 di << "DPrsStd_AISTransparency : Error" << "\n";
343 //=======================================================================
344 //function : DPrsStd_AISDefaultTransparency
345 //purpose : AISDefaultTransparency (DOC,entry)
346 //=======================================================================
348 static Standard_Integer DPrsStd_AISDefaultTransparency (Draw_Interpretor& di,
353 Handle(TDocStd_Document) D;
354 if (!DDocStd::GetDocument(arg[1],D)) return 1;
356 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
358 Handle(TPrsStd_AISPresentation) prs;
359 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
360 prs->UnsetTransparency();
361 TPrsStd_AISViewer::Update(L);
365 di << "DPrsStd_AISDefaultTransparency : Error" << "\n";
369 //=======================================================================
370 //function : DPrsStd_AISColor
371 //purpose : AISColor (DOC,entry,[color])
372 //=======================================================================
374 static Standard_Integer DPrsStd_AISColor (Draw_Interpretor& di,
379 Handle(TDocStd_Document) D;
380 if (!DDocStd::GetDocument(arg[1],D)) return 1;
382 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
384 Handle(TPrsStd_AISViewer) viewer;
385 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
387 Handle(TPrsStd_AISPresentation) prs;
388 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
390 prs->SetColor((Quantity_NameOfColor)Draw::Atoi(arg[3]));
391 TPrsStd_AISViewer::Update(L);
394 if (prs->HasOwnColor()){
395 di << "Color = " << prs->Color() << "\n";
399 di << "DPrsStd_AISColor: Warning : Color wasn't set" << "\n";
405 di << "DPrsStd_AISColor : Error" << "\n";
409 //=======================================================================
410 //function : DPrsStd_AISDefaultColor
411 //purpose : AISDefaultColor (DOC,entry)
412 //=======================================================================
414 static Standard_Integer DPrsStd_AISDefaultColor (Draw_Interpretor& di,
419 Handle(TDocStd_Document) D;
420 if (!DDocStd::GetDocument(arg[1],D)) return 1;
422 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
424 Handle(TPrsStd_AISViewer) viewer;
425 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
427 Handle(TPrsStd_AISPresentation) prs;
428 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
430 TPrsStd_AISViewer::Update(L);
434 di << "DPrsStd_AISDefaultColor : Error" << "\n";
438 //=======================================================================
439 //function : DPrsStd_AISMaterial
440 //purpose : AISMaterial (DOC,entry,[material])
441 //=======================================================================
443 static Standard_Integer DPrsStd_AISMaterial (Draw_Interpretor& di,
448 Handle(TDocStd_Document) D;
449 if (!DDocStd::GetDocument(arg[1],D)) return 1;
451 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
453 Handle(TPrsStd_AISViewer) viewer;
454 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
456 Handle(TPrsStd_AISPresentation) prs;
457 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
459 prs->SetMaterial((Graphic3d_NameOfMaterial)Draw::Atoi(arg[3]));
460 TPrsStd_AISViewer::Update(L);
463 if (prs->HasOwnMaterial()){
464 di << "Material = " << prs->Material() << "\n";
468 di << "DPrsStd_AISMaterial: Warning : Material wasn't set" << "\n";
475 di << "DPrsStd_AISMaterial : Error" << "\n";
479 //=======================================================================
480 //function : DPrsStd_AISDefaultMaterial
481 //purpose : AISDefaultMaterial (DOC,entry)
482 //=======================================================================
484 static Standard_Integer DPrsStd_AISDefaultMaterial (Draw_Interpretor& di,
489 Handle(TDocStd_Document) D;
490 if (!DDocStd::GetDocument(arg[1],D)) return 1;
492 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
494 Handle(TPrsStd_AISViewer) viewer;
495 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
497 Handle(TPrsStd_AISPresentation) prs;
498 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
499 prs->UnsetMaterial();
500 TPrsStd_AISViewer::Update(L);
504 di << "DPrsStd_AISDefaultMaterial : Error" << "\n";
508 //=======================================================================
509 //function : DPrsStd_AISHasOwnColor
510 //purpose : AISHasOwnColor (DOC,entry)
512 //=======================================================================
514 static Standard_Integer DPrsStd_AISHasOwnColor (Draw_Interpretor& di,
520 di << "DPrsStd_AISHasOwnColor : Warning : too many arguments" << "\n";
522 Handle(TDocStd_Document) D;
523 if (!DDocStd::GetDocument(arg[1],D)) return 1;
525 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
527 Handle(TPrsStd_AISViewer) viewer;
528 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
530 Handle(TPrsStd_AISPresentation) prs;
531 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
532 di<<Standard_Integer(prs->HasOwnColor());
537 di << "DPrsStd_AISHasOwnColor : Error" << "\n";
542 //=======================================================================
543 //function : DPrsStd_AISHasOwnMaterial
544 //purpose : AISHasOwnMaterial (DOC,entry)
546 //=======================================================================
548 static Standard_Integer DPrsStd_AISHasOwnMaterial (Draw_Interpretor& di,
554 di << "DPrsStd_AISHasOwnMaterial : Warning : too many arguments" << "\n";
556 Handle(TDocStd_Document) D;
557 if (!DDocStd::GetDocument(arg[1],D)) return 1;
559 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
561 Handle(TPrsStd_AISViewer) viewer;
562 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
564 Handle(TPrsStd_AISPresentation) prs;
565 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
566 di<<Standard_Integer(prs->HasOwnMaterial());
571 di << "DPrsStd_AISHasOwnMaterial : Error" << "\n";
576 //=======================================================================
577 //function : DPrsStd_AISHasOwnTransparency
578 //purpose : AISHasOwnColor (DOC,entry)
580 //=======================================================================
582 static Standard_Integer DPrsStd_AISHasOwnTransparency (Draw_Interpretor& di,
588 di << "DPrsStd_AISHasOwnTransparency : Warning : too many arguments" << "\n";
590 Handle(TDocStd_Document) D;
591 if (!DDocStd::GetDocument(arg[1],D)) return 1;
593 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
595 Handle(TPrsStd_AISViewer) viewer;
596 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
598 Handle(TPrsStd_AISPresentation) prs;
599 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
600 di<<Standard_Integer(prs->HasOwnTransparency());
605 di << "DPrsStd_AISHasOwnTransparency : Error" << "\n";
610 //=======================================================================
611 //function : AISPresentationCommands
613 //=======================================================================
616 void DPrsStd::AISPresentationCommands (Draw_Interpretor& theCommands)
618 static Standard_Boolean done = Standard_False;
620 done = Standard_True;
621 const char* g = "DPrsStd : standard presentation commands" ;
623 // standard commands working on AISPresentation
625 theCommands.Add ("AISDisplay",
626 "AISDisplay (DOC, entry, [not_update])",
627 __FILE__, DPrsStd_AISDisplay, g);
629 theCommands.Add ("AISErase",
630 "AISErase (DOC, entry)",
631 __FILE__, DPrsStd_AISErase, g);
633 theCommands.Add ("AISUpdate",
634 "AISUpdate (DOC, entry)",
635 __FILE__, DPrsStd_AISUpdate, g);
637 theCommands.Add ("AISSet",
638 "AISSet (DOC, entry, ID)",
639 __FILE__, DPrsStd_AISSet, g);
641 theCommands.Add ("AISDriver",
642 "AISDriver (DOC, entry, [ID]) - returns DriverGUID stored in attribute or sets new one",
643 __FILE__, DPrsStd_AISDriver, g);
645 theCommands.Add ("AISUnset",
646 "AISUnset (DOC, entry)",
647 __FILE__, DPrsStd_AISUnset, g);
649 theCommands.Add ("AISTransparency",
650 "AISTransparency (DOC, entry, [real])",
651 __FILE__, DPrsStd_AISTransparency, g);
653 theCommands.Add ("AISDefaultTransparency",
654 "AISDefaultTransparency (DOC, entry)",
655 __FILE__, DPrsStd_AISDefaultTransparency, g);
657 theCommands.Add ("AISHasOwnTransparency",
658 "AISHasOwnTransparency (DOC, entry) | AISHasOwnTransparency return Boolean",
659 __FILE__, DPrsStd_AISHasOwnTransparency, g);
661 theCommands.Add ("AISDefaultColor",
662 "AISDefaultColor (DOC, entry)",
663 __FILE__, DPrsStd_AISDefaultColor, g);
665 theCommands.Add ("AISColor",
666 "AISColor (DOC, entry, [color])",
667 __FILE__, DPrsStd_AISColor, g);
669 theCommands.Add ("AISHasOwnColor",
670 "AISHasOwnColor (DOC, entry) | AISHasOwnColor return Boolean",
671 __FILE__, DPrsStd_AISHasOwnColor, g);
673 theCommands.Add ("AISMaterial",
674 "AISMaterial (DOC, entry, [material])",
675 __FILE__, DPrsStd_AISMaterial, g);
677 theCommands.Add ("AISDefaultMaterial",
678 "AISDefaultMaterial (DOC, entry)",
679 __FILE__, DPrsStd_AISDefaultMaterial, g);
681 theCommands.Add ("AISHasOwnMaterial",
682 "AISHasOwnMaterial (DOC, entry) | AISHasOwnMaterial return Boolean",
683 __FILE__, DPrsStd_AISHasOwnMaterial, g);
685 theCommands.Add ("AISRemove",
686 "AISRemove (DOC, entry)",
687 __FILE__, DPrsStd_AISRemove, g);