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 <ViewerTest_Tool.hxx>
44 #include <V3d_View.hxx>
45 #include <TCollection_ExtendedString.hxx>
46 #include <Quantity_NameOfColor.hxx>
47 #include <Graphic3d_NameOfMaterial.hxx>
49 #include <TDataXtd_Axis.hxx>
50 #include <TDataXtd_Constraint.hxx>
51 #include <TDataXtd_Geometry.hxx>
52 #include <TNaming_NamedShape.hxx>
53 #include <TDataXtd_Plane.hxx>
54 #include <TDataXtd_Point.hxx>
55 #include <Standard_PCharacter.hxx>
57 //#include <TSketchStd_Geometry.hxx>
58 //#include <TSketchStd_Edge.hxx>
60 //=======================================================================
61 //function : DPrsStd_AISDisplay
62 //purpose : DDisplay (DOC,entry, not_update)
63 //=======================================================================
65 static Standard_Integer DPrsStd_AISDisplay (Draw_Interpretor&,
70 Handle(TDocStd_Document) D;
71 if (!DDocStd::GetDocument(arg[1],D)) return 1;
73 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
74 Handle(TPrsStd_AISPresentation) prs;
75 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
77 prs->Display(Standard_True);
78 TPrsStd_AISViewer::Update(L);
83 TPrsStd_AISViewer::Update(L);
88 //=======================================================================
89 //function : DPrsStd_AISRemove
90 //purpose : AISRemove (DOC,entry)
91 //=======================================================================
93 static Standard_Integer DPrsStd_AISRemove (Draw_Interpretor& di,
98 Handle(TDocStd_Document) D;
99 if (!DDocStd::GetDocument(arg[1],D)) return 1;
101 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
102 Handle(TPrsStd_AISPresentation) P;
103 if(!L.FindAttribute(TPrsStd_AISPresentation::GetID(), P)) return 1;
104 P->Erase(Standard_True);
105 TPrsStd_AISViewer::Update(L);
108 di << "DPrsStd_AISRedisplay : Error" << "\n";
113 //=======================================================================
114 //function : DPrsStd_AISErase
115 //purpose : AISErase (DOC,entry)
116 //=======================================================================
118 static Standard_Integer DPrsStd_AISErase (Draw_Interpretor& di,
123 Handle(TDocStd_Document) D;
124 if (!DDocStd::GetDocument(arg[1],D)) return 1;
126 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
127 Handle(TPrsStd_AISPresentation) prs;
128 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
130 TPrsStd_AISViewer::Update(L);
133 di << "DPrsStd_AISErase : Error" << "\n";
137 //=======================================================================
138 //function : DPrsStd_AISUpdate
139 //purpose : AISUpdate (DOC,entry)
140 //=======================================================================
142 static Standard_Integer DPrsStd_AISUpdate (Draw_Interpretor& di,
147 Handle(TDocStd_Document) D;
148 if (!DDocStd::GetDocument(arg[1],D)) return 1;
150 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
151 Handle(TPrsStd_AISPresentation) prs;
152 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
154 TPrsStd_AISViewer::Update(L);
157 di << "DPrsStd_AISUpdate : Error" << "\n";
162 //=======================================================================
163 //function : DPrsStd_AISSet
164 //purpose : AISSet (DOC,entry, id)
165 //=======================================================================
167 static Standard_Integer DPrsStd_AISSet (Draw_Interpretor& di,
172 Handle(TDocStd_Document) D;
173 if (!DDocStd::GetDocument(arg[1],D)) return 1;
175 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
177 TCollection_ExtendedString str = arg[3];
179 cout << "Inputed parameter > " << str << endl;
181 if ( str == "A" ) //axis
182 guid = TDataXtd_Axis::GetID(); //"2a96b601-ec8b-11d0-bee7-080009dc3333"
183 else if( str == "C") //constraint
184 guid = TDataXtd_Constraint::GetID(); //"2a96b602-ec8b-11d0-bee7-080009dc3333"
185 else if( str == "NS" ) //namedshape
186 guid = TNaming_NamedShape::GetID(); //"c4ef4200-568f-11d1-8940-080009dc3333"
187 else if( str == "G" ) //geometry
188 guid = TDataXtd_Geometry::GetID(); //"2a96b604-ec8b-11d0-bee7-080009dc3333"
189 else if( str == "PL" ) //plane
190 guid = TDataXtd_Plane::GetID(); //"2a96b60c-ec8b-11d0-bee7-080009dc3333"
191 else if( str == "PT" ) //point
192 guid = TDataXtd_Point::GetID(); //"2a96b60d-ec8b-11d0-bee7-080009dc3333"
193 // else if( str == "SG" ) //TSketch_Geometry
194 // guid = TSketchStd_Geometry::GetID(); //"b3aac909-5b78-11d1-8940-080009dc3333"
195 // else if( str == "E" ) //TSketch_Edge
196 // guid = TSketchStd_Edge::GetID(); //"b3aac90a-5b78-11d1-8940-080009dc3333"
198 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, guid);
200 cout << "Driver GUID = ";
201 prs->GetDriverGUID().ShallowDump(cout);
204 Standard_Character resS[37];
205 Standard_PCharacter presS;
207 guid.ToCString(presS);
211 di << "DPrsStd_AISSet : Error" << "\n";
215 //=======================================================================
216 //function : DPrsStd_AISDriver
217 //purpose : AISDriver (DOC,entry, [ID])
218 //=======================================================================
220 static Standard_Integer DPrsStd_AISDriver (Draw_Interpretor& di,
225 Handle(TDocStd_Document) D;
226 if (!DDocStd::GetDocument(arg[1],D)) return 1;
228 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
231 Handle(TPrsStd_AISPresentation) prs;
232 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
234 guid = prs->GetDriverGUID();
235 Standard_Character str[37];
236 Standard_PCharacter pstr;
238 guid.ToCString( pstr );
243 TCollection_ExtendedString str = arg[3];
245 cout << "Inputed parameter > " << str << endl;
247 if ( str == "A" ) //axis
248 guid = TDataXtd_Axis::GetID(); //"2a96b601-ec8b-11d0-bee7-080009dc3333"
249 else if( str == "C") //constraint
250 guid = TDataXtd_Constraint::GetID(); //"2a96b602-ec8b-11d0-bee7-080009dc3333"
251 else if( str == "NS" ) //namedshape
252 guid = TNaming_NamedShape::GetID(); //"c4ef4200-568f-11d1-8940-080009dc3333"
253 else if( str == "G" ) //geometry
254 guid = TDataXtd_Geometry::GetID(); //"2a96b604-ec8b-11d0-bee7-080009dc3333"
255 else if( str == "PL" ) //plane
256 guid = TDataXtd_Plane::GetID(); //"2a96b60c-ec8b-11d0-bee7-080009dc3333"
257 else if( str == "PT" ) //point
258 guid = TDataXtd_Point::GetID(); //"2a96b60d-ec8b-11d0-bee7-080009dc3333"
259 // else if( str == "SG" ) //TSketch_Geometry
260 // guid = TSketchStd_Geometry::GetID(); //"b3aac909-5b78-11d1-8940-080009dc3333"
261 // else if( str == "E" ) //TSketch_Edge
262 // guid = TSketchStd_Edge::GetID(); //"b3aac90a-5b78-11d1-8940-080009dc3333"
264 prs->SetDriverGUID(guid);
265 Standard_Character resS[37];
266 Standard_PCharacter presS;
267 //modified by NIZNHY-PKV Tue Apr 22 16:15:02 2008f
269 //modified by NIZNHY-PKV Tue Apr 22 16:15:05 2008t
270 guid.ToCString( presS );
276 di << "DPrsStd_AISDriver : Error" << "\n";
280 //=======================================================================
281 //function : DPrsStd_AISUnset
282 //purpose : AISUnset (DOC,entry)
283 //=======================================================================
285 static Standard_Integer DPrsStd_AISUnset (Draw_Interpretor& di,
290 Handle(TDocStd_Document) D;
291 if (!DDocStd::GetDocument(arg[1],D)) return 1;
293 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
294 TPrsStd_AISPresentation::Unset(L);
295 TPrsStd_AISViewer::Update(L);
298 di << "DPrsStd_AISDriver : Error" << "\n";
303 //=======================================================================
304 //function : DPrsStd_AISTransparency
305 //purpose : AISTransparency (DOC,entry,[real])
306 //=======================================================================
308 static Standard_Integer DPrsStd_AISTransparency (Draw_Interpretor& di,
313 Handle(TDocStd_Document) D;
314 if (!DDocStd::GetDocument(arg[1],D)) return 1;
316 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
318 Handle(TPrsStd_AISViewer) viewer;
319 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
321 Handle(TPrsStd_AISPresentation) prs;
322 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
324 prs->SetTransparency(Draw::Atof(arg[3]));
325 TPrsStd_AISViewer::Update(L);
328 if (prs->HasOwnTransparency()){
329 di << "Transparency = " << prs->Transparency() << "\n";
330 di<<prs->Transparency();
333 di << "DPrsStd_AISTransparency: Warning : Transparency wasn't set" << "\n";
340 di << "DPrsStd_AISTransparency : Error" << "\n";
344 //=======================================================================
345 //function : DPrsStd_AISDefaultTransparency
346 //purpose : AISDefaultTransparency (DOC,entry)
347 //=======================================================================
349 static Standard_Integer DPrsStd_AISDefaultTransparency (Draw_Interpretor& di,
354 Handle(TDocStd_Document) D;
355 if (!DDocStd::GetDocument(arg[1],D)) return 1;
357 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
359 Handle(TPrsStd_AISPresentation) prs;
360 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
361 prs->UnsetTransparency();
362 TPrsStd_AISViewer::Update(L);
366 di << "DPrsStd_AISDefaultTransparency : Error" << "\n";
370 //=======================================================================
371 //function : DPrsStd_AISColor
372 //purpose : AISColor (DOC,entry,[color])
373 //=======================================================================
375 static Standard_Integer DPrsStd_AISColor (Draw_Interpretor& di,
380 Handle(TDocStd_Document) D;
381 if (!DDocStd::GetDocument(arg[1],D)) return 1;
383 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
385 Handle(TPrsStd_AISViewer) viewer;
386 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
388 Handle(TPrsStd_AISPresentation) prs;
389 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
391 prs->SetColor((Quantity_NameOfColor)Draw::Atoi(arg[3]));
392 TPrsStd_AISViewer::Update(L);
395 if (prs->HasOwnColor()){
396 di << "Color = " << prs->Color() << "\n";
400 di << "DPrsStd_AISColor: Warning : Color wasn't set" << "\n";
406 di << "DPrsStd_AISColor : Error" << "\n";
410 //=======================================================================
411 //function : DPrsStd_AISDefaultColor
412 //purpose : AISDefaultColor (DOC,entry)
413 //=======================================================================
415 static Standard_Integer DPrsStd_AISDefaultColor (Draw_Interpretor& di,
420 Handle(TDocStd_Document) D;
421 if (!DDocStd::GetDocument(arg[1],D)) return 1;
423 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
425 Handle(TPrsStd_AISViewer) viewer;
426 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
428 Handle(TPrsStd_AISPresentation) prs;
429 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
431 TPrsStd_AISViewer::Update(L);
435 di << "DPrsStd_AISDefaultColor : Error" << "\n";
439 //=======================================================================
440 //function : DPrsStd_AISMaterial
441 //purpose : AISMaterial (DOC,entry,[material])
442 //=======================================================================
444 static Standard_Integer DPrsStd_AISMaterial (Draw_Interpretor& di,
449 Handle(TDocStd_Document) D;
450 if (!DDocStd::GetDocument(arg[1],D)) return 1;
452 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
454 Handle(TPrsStd_AISViewer) viewer;
455 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
457 Handle(TPrsStd_AISPresentation) prs;
458 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
460 prs->SetMaterial((Graphic3d_NameOfMaterial)Draw::Atoi(arg[3]));
461 TPrsStd_AISViewer::Update(L);
464 if (prs->HasOwnMaterial()){
465 di << "Material = " << prs->Material() << "\n";
469 di << "DPrsStd_AISMaterial: Warning : Material wasn't set" << "\n";
476 di << "DPrsStd_AISMaterial : Error" << "\n";
480 //=======================================================================
481 //function : DPrsStd_AISDefaultMaterial
482 //purpose : AISDefaultMaterial (DOC,entry)
483 //=======================================================================
485 static Standard_Integer DPrsStd_AISDefaultMaterial (Draw_Interpretor& di,
490 Handle(TDocStd_Document) D;
491 if (!DDocStd::GetDocument(arg[1],D)) return 1;
493 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
495 Handle(TPrsStd_AISViewer) viewer;
496 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
498 Handle(TPrsStd_AISPresentation) prs;
499 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
500 prs->UnsetMaterial();
501 TPrsStd_AISViewer::Update(L);
505 di << "DPrsStd_AISDefaultMaterial : Error" << "\n";
509 //=======================================================================
510 //function : DPrsStd_AISHasOwnColor
511 //purpose : AISHasOwnColor (DOC,entry)
513 //=======================================================================
515 static Standard_Integer DPrsStd_AISHasOwnColor (Draw_Interpretor& di,
521 di << "DPrsStd_AISHasOwnColor : Warning : too many arguments" << "\n";
523 Handle(TDocStd_Document) D;
524 if (!DDocStd::GetDocument(arg[1],D)) return 1;
526 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
528 Handle(TPrsStd_AISViewer) viewer;
529 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
531 Handle(TPrsStd_AISPresentation) prs;
532 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
533 di<<Standard_Integer(prs->HasOwnColor());
538 di << "DPrsStd_AISHasOwnColor : Error" << "\n";
543 //=======================================================================
544 //function : DPrsStd_AISHasOwnMaterial
545 //purpose : AISHasOwnMaterial (DOC,entry)
547 //=======================================================================
549 static Standard_Integer DPrsStd_AISHasOwnMaterial (Draw_Interpretor& di,
555 di << "DPrsStd_AISHasOwnMaterial : Warning : too many arguments" << "\n";
557 Handle(TDocStd_Document) D;
558 if (!DDocStd::GetDocument(arg[1],D)) return 1;
560 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
562 Handle(TPrsStd_AISViewer) viewer;
563 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
565 Handle(TPrsStd_AISPresentation) prs;
566 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
567 di<<Standard_Integer(prs->HasOwnMaterial());
572 di << "DPrsStd_AISHasOwnMaterial : Error" << "\n";
577 //=======================================================================
578 //function : DPrsStd_AISHasOwnTransparency
579 //purpose : AISHasOwnColor (DOC,entry)
581 //=======================================================================
583 static Standard_Integer DPrsStd_AISHasOwnTransparency (Draw_Interpretor& di,
589 di << "DPrsStd_AISHasOwnTransparency : Warning : too many arguments" << "\n";
591 Handle(TDocStd_Document) D;
592 if (!DDocStd::GetDocument(arg[1],D)) return 1;
594 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
596 Handle(TPrsStd_AISViewer) viewer;
597 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
599 Handle(TPrsStd_AISPresentation) prs;
600 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
601 di<<Standard_Integer(prs->HasOwnTransparency());
606 di << "DPrsStd_AISHasOwnTransparency : Error" << "\n";
611 //=======================================================================
612 //function : AISPresentationCommands
614 //=======================================================================
617 void DPrsStd::AISPresentationCommands (Draw_Interpretor& theCommands)
619 static Standard_Boolean done = Standard_False;
621 done = Standard_True;
622 const char* g = "DPrsStd : standard presentation commands" ;
624 // standard commands working on AISPresentation
626 theCommands.Add ("AISDisplay",
627 "AISDisplay (DOC, entry, [not_update])",
628 __FILE__, DPrsStd_AISDisplay, g);
630 theCommands.Add ("AISErase",
631 "AISErase (DOC, entry)",
632 __FILE__, DPrsStd_AISErase, g);
634 theCommands.Add ("AISUpdate",
635 "AISUpdate (DOC, entry)",
636 __FILE__, DPrsStd_AISUpdate, g);
638 theCommands.Add ("AISSet",
639 "AISSet (DOC, entry, ID)",
640 __FILE__, DPrsStd_AISSet, g);
642 theCommands.Add ("AISDriver",
643 "AISDriver (DOC, entry, [ID]) - returns DriverGUID stored in attribute or sets new one",
644 __FILE__, DPrsStd_AISDriver, g);
646 theCommands.Add ("AISUnset",
647 "AISUnset (DOC, entry)",
648 __FILE__, DPrsStd_AISUnset, g);
650 theCommands.Add ("AISTransparency",
651 "AISTransparency (DOC, entry, [real])",
652 __FILE__, DPrsStd_AISTransparency, g);
654 theCommands.Add ("AISDefaultTransparency",
655 "AISDefaultTransparency (DOC, entry)",
656 __FILE__, DPrsStd_AISDefaultTransparency, g);
658 theCommands.Add ("AISHasOwnTransparency",
659 "AISHasOwnTransparency (DOC, entry) | AISHasOwnTransparency return Boolean",
660 __FILE__, DPrsStd_AISHasOwnTransparency, g);
662 theCommands.Add ("AISDefaultColor",
663 "AISDefaultColor (DOC, entry)",
664 __FILE__, DPrsStd_AISDefaultColor, g);
666 theCommands.Add ("AISColor",
667 "AISColor (DOC, entry, [color])",
668 __FILE__, DPrsStd_AISColor, g);
670 theCommands.Add ("AISHasOwnColor",
671 "AISHasOwnColor (DOC, entry) | AISHasOwnColor return Boolean",
672 __FILE__, DPrsStd_AISHasOwnColor, g);
674 theCommands.Add ("AISMaterial",
675 "AISMaterial (DOC, entry, [material])",
676 __FILE__, DPrsStd_AISMaterial, g);
678 theCommands.Add ("AISDefaultMaterial",
679 "AISDefaultMaterial (DOC, entry)",
680 __FILE__, DPrsStd_AISDefaultMaterial, g);
682 theCommands.Add ("AISHasOwnMaterial",
683 "AISHasOwnMaterial (DOC, entry) | AISHasOwnMaterial return Boolean",
684 __FILE__, DPrsStd_AISHasOwnMaterial, g);
686 theCommands.Add ("AISRemove",
687 "AISRemove (DOC, entry)",
688 __FILE__, DPrsStd_AISRemove, g);