1 // Created on: 1998-10-07
2 // Created by: Denis PASCAL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <DPrsStd.hxx>
25 #include <Draw_Appli.hxx>
26 #include <Draw_Interpretor.hxx>
27 #include <Draw_ColorKind.hxx>
28 #include <TCollection_AsciiString.hxx>
29 #include <TDocStd_Document.hxx>
30 #include <TDF_Label.hxx>
31 #include <TDF_Data.hxx>
33 #include <DDocStd.hxx>
34 #include <ViewerTest.hxx>
37 #include <V3d_View.hxx>
42 #include <TPrsStd_AISPresentation.hxx>
43 #include <TPrsStd_AISViewer.hxx>
44 #include <ViewerTest.hxx>
45 #include <AIS_InteractiveContext.hxx>
46 #include <AIS_InteractiveObject.hxx>
47 #include <AIS_Drawer.hxx>
48 #include <ViewerTest.hxx>
49 #include <ViewerTest_Tool.hxx>
50 #include <V3d_View.hxx>
51 #include <TCollection_ExtendedString.hxx>
52 #include <Quantity_NameOfColor.hxx>
53 #include <Graphic3d_NameOfMaterial.hxx>
55 #include <TDataXtd_Axis.hxx>
56 #include <TDataXtd_Constraint.hxx>
57 #include <TDataXtd_Geometry.hxx>
58 #include <TNaming_NamedShape.hxx>
59 #include <TDataXtd_Plane.hxx>
60 #include <TDataXtd_Point.hxx>
61 #include <Standard_PCharacter.hxx>
63 //#include <TSketchStd_Geometry.hxx>
64 //#include <TSketchStd_Edge.hxx>
66 //=======================================================================
67 //function : DPrsStd_AISDisplay
68 //purpose : DDisplay (DOC,entry, not_update)
69 //=======================================================================
71 static Standard_Integer DPrsStd_AISDisplay (Draw_Interpretor& di,
76 Handle(TDocStd_Document) D;
77 if (!DDocStd::GetDocument(arg[1],D)) return 1;
79 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
80 Handle(TPrsStd_AISPresentation) prs;
81 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
83 prs->Display(Standard_True);
84 TPrsStd_AISViewer::Update(L);
89 TPrsStd_AISViewer::Update(L);
92 di << "DPrsStd_AISDisplay : Error" << "\n";
96 //=======================================================================
97 //function : DPrsStd_AISRemove
98 //purpose : AISRemove (DOC,entry)
99 //=======================================================================
101 static Standard_Integer DPrsStd_AISRemove (Draw_Interpretor& di,
106 Handle(TDocStd_Document) D;
107 if (!DDocStd::GetDocument(arg[1],D)) return 1;
109 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
110 Handle(TPrsStd_AISPresentation) P;
111 if(!L.FindAttribute(TPrsStd_AISPresentation::GetID(), P)) return 1;
112 P->Erase(Standard_True);
113 TPrsStd_AISViewer::Update(L);
116 di << "DPrsStd_AISRedisplay : Error" << "\n";
121 //=======================================================================
122 //function : DPrsStd_AISErase
123 //purpose : AISErase (DOC,entry)
124 //=======================================================================
126 static Standard_Integer DPrsStd_AISErase (Draw_Interpretor& di,
131 Handle(TDocStd_Document) D;
132 if (!DDocStd::GetDocument(arg[1],D)) return 1;
134 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
135 Handle(TPrsStd_AISPresentation) prs;
136 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
138 TPrsStd_AISViewer::Update(L);
141 di << "DPrsStd_AISErase : Error" << "\n";
145 //=======================================================================
146 //function : DPrsStd_AISUpdate
147 //purpose : AISUpdate (DOC,entry)
148 //=======================================================================
150 static Standard_Integer DPrsStd_AISUpdate (Draw_Interpretor& di,
155 Handle(TDocStd_Document) D;
156 if (!DDocStd::GetDocument(arg[1],D)) return 1;
158 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
159 Handle(TPrsStd_AISPresentation) prs;
160 if(!L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) return 1;
162 TPrsStd_AISViewer::Update(L);
165 di << "DPrsStd_AISUpdate : Error" << "\n";
170 //=======================================================================
171 //function : DPrsStd_AISSet
172 //purpose : AISSet (DOC,entry, id)
173 //=======================================================================
175 static Standard_Integer DPrsStd_AISSet (Draw_Interpretor& di,
180 Handle(TDocStd_Document) D;
181 if (!DDocStd::GetDocument(arg[1],D)) return 1;
183 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
185 TCollection_ExtendedString str = arg[3];
187 cout << "Inputed parameter > " << str << endl;
189 if ( str == "A" ) //axis
190 guid = TDataXtd_Axis::GetID(); //"2a96b601-ec8b-11d0-bee7-080009dc3333"
191 else if( str == "C") //constraint
192 guid = TDataXtd_Constraint::GetID(); //"2a96b602-ec8b-11d0-bee7-080009dc3333"
193 else if( str == "NS" ) //namedshape
194 guid = TNaming_NamedShape::GetID(); //"c4ef4200-568f-11d1-8940-080009dc3333"
195 else if( str == "G" ) //geometry
196 guid = TDataXtd_Geometry::GetID(); //"2a96b604-ec8b-11d0-bee7-080009dc3333"
197 else if( str == "PL" ) //plane
198 guid = TDataXtd_Plane::GetID(); //"2a96b60c-ec8b-11d0-bee7-080009dc3333"
199 else if( str == "PT" ) //point
200 guid = TDataXtd_Point::GetID(); //"2a96b60d-ec8b-11d0-bee7-080009dc3333"
201 // else if( str == "SG" ) //TSketch_Geometry
202 // guid = TSketchStd_Geometry::GetID(); //"b3aac909-5b78-11d1-8940-080009dc3333"
203 // else if( str == "E" ) //TSketch_Edge
204 // guid = TSketchStd_Edge::GetID(); //"b3aac90a-5b78-11d1-8940-080009dc3333"
206 Handle(TPrsStd_AISPresentation) prs= TPrsStd_AISPresentation::Set(L, guid);
208 cout << "Driver GUID = ";
209 prs->GetDriverGUID().ShallowDump(cout);
212 Standard_Character resS[37];
213 Standard_PCharacter presS;
215 guid.ToCString(presS);
219 di << "DPrsStd_AISSet : Error" << "\n";
223 //=======================================================================
224 //function : DPrsStd_AISDriver
225 //purpose : AISDriver (DOC,entry, [ID])
226 //=======================================================================
228 static Standard_Integer DPrsStd_AISDriver (Draw_Interpretor& di,
233 Handle(TDocStd_Document) D;
234 if (!DDocStd::GetDocument(arg[1],D)) return 1;
236 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
239 Handle(TPrsStd_AISPresentation) prs;
240 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
242 guid = prs->GetDriverGUID();
243 Standard_Character str[37];
244 Standard_PCharacter pstr;
246 guid.ToCString( pstr );
251 TCollection_ExtendedString str = arg[3];
253 cout << "Inputed parameter > " << str << endl;
255 if ( str == "A" ) //axis
256 guid = TDataXtd_Axis::GetID(); //"2a96b601-ec8b-11d0-bee7-080009dc3333"
257 else if( str == "C") //constraint
258 guid = TDataXtd_Constraint::GetID(); //"2a96b602-ec8b-11d0-bee7-080009dc3333"
259 else if( str == "NS" ) //namedshape
260 guid = TNaming_NamedShape::GetID(); //"c4ef4200-568f-11d1-8940-080009dc3333"
261 else if( str == "G" ) //geometry
262 guid = TDataXtd_Geometry::GetID(); //"2a96b604-ec8b-11d0-bee7-080009dc3333"
263 else if( str == "PL" ) //plane
264 guid = TDataXtd_Plane::GetID(); //"2a96b60c-ec8b-11d0-bee7-080009dc3333"
265 else if( str == "PT" ) //point
266 guid = TDataXtd_Point::GetID(); //"2a96b60d-ec8b-11d0-bee7-080009dc3333"
267 // else if( str == "SG" ) //TSketch_Geometry
268 // guid = TSketchStd_Geometry::GetID(); //"b3aac909-5b78-11d1-8940-080009dc3333"
269 // else if( str == "E" ) //TSketch_Edge
270 // guid = TSketchStd_Edge::GetID(); //"b3aac90a-5b78-11d1-8940-080009dc3333"
272 prs->SetDriverGUID(guid);
273 Standard_Character resS[37];
274 Standard_PCharacter presS;
275 //modified by NIZNHY-PKV Tue Apr 22 16:15:02 2008f
277 //modified by NIZNHY-PKV Tue Apr 22 16:15:05 2008t
278 guid.ToCString( presS );
284 di << "DPrsStd_AISDriver : Error" << "\n";
288 //=======================================================================
289 //function : DPrsStd_AISUnset
290 //purpose : AISUnset (DOC,entry)
291 //=======================================================================
293 static Standard_Integer DPrsStd_AISUnset (Draw_Interpretor& di,
298 Handle(TDocStd_Document) D;
299 if (!DDocStd::GetDocument(arg[1],D)) return 1;
301 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
302 TPrsStd_AISPresentation::Unset(L);
303 TPrsStd_AISViewer::Update(L);
306 di << "DPrsStd_AISDriver : Error" << "\n";
311 //=======================================================================
312 //function : DPrsStd_AISTransparency
313 //purpose : AISTransparency (DOC,entry,[real])
314 //=======================================================================
316 static Standard_Integer DPrsStd_AISTransparency (Draw_Interpretor& di,
321 Handle(TDocStd_Document) D;
322 if (!DDocStd::GetDocument(arg[1],D)) return 1;
324 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
326 Handle(TPrsStd_AISViewer) viewer;
327 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
329 Handle(TPrsStd_AISPresentation) prs;
330 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
332 prs->SetTransparency(atof(arg[3]));
333 TPrsStd_AISViewer::Update(L);
336 if (prs->HasOwnTransparency()){
337 di << "Transparency = " << prs->Transparency() << "\n";
338 di<<prs->Transparency();
341 di << "DPrsStd_AISTransparency: Warning : Transparency wasn't set" << "\n";
348 di << "DPrsStd_AISTransparency : Error" << "\n";
352 //=======================================================================
353 //function : DPrsStd_AISDefaultTransparency
354 //purpose : AISDefaultTransparency (DOC,entry)
355 //=======================================================================
357 static Standard_Integer DPrsStd_AISDefaultTransparency (Draw_Interpretor& di,
362 Handle(TDocStd_Document) D;
363 if (!DDocStd::GetDocument(arg[1],D)) return 1;
365 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
367 Handle(TPrsStd_AISPresentation) prs;
368 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
369 prs->UnsetTransparency();
370 TPrsStd_AISViewer::Update(L);
374 di << "DPrsStd_AISDefaultTransparency : Error" << "\n";
378 //=======================================================================
379 //function : DPrsStd_AISColor
380 //purpose : AISColor (DOC,entry,[color])
381 //=======================================================================
383 static Standard_Integer DPrsStd_AISColor (Draw_Interpretor& di,
388 Handle(TDocStd_Document) D;
389 if (!DDocStd::GetDocument(arg[1],D)) return 1;
391 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
393 Handle(TPrsStd_AISViewer) viewer;
394 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
396 Handle(TPrsStd_AISPresentation) prs;
397 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
399 prs->SetColor((Quantity_NameOfColor)atoi(arg[3]));
400 TPrsStd_AISViewer::Update(L);
403 if (prs->HasOwnColor()){
404 di << "Color = " << prs->Color() << "\n";
408 di << "DPrsStd_AISColor: Warning : Color wasn't set" << "\n";
414 di << "DPrsStd_AISColor : Error" << "\n";
418 //=======================================================================
419 //function : DPrsStd_AISDefaultColor
420 //purpose : AISDefaultColor (DOC,entry)
421 //=======================================================================
423 static Standard_Integer DPrsStd_AISDefaultColor (Draw_Interpretor& di,
428 Handle(TDocStd_Document) D;
429 if (!DDocStd::GetDocument(arg[1],D)) return 1;
431 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
433 Handle(TPrsStd_AISViewer) viewer;
434 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
436 Handle(TPrsStd_AISPresentation) prs;
437 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
439 TPrsStd_AISViewer::Update(L);
443 di << "DPrsStd_AISDefaultColor : Error" << "\n";
447 //=======================================================================
448 //function : DPrsStd_AISMaterial
449 //purpose : AISMaterial (DOC,entry,[material])
450 //=======================================================================
452 static Standard_Integer DPrsStd_AISMaterial (Draw_Interpretor& di,
457 Handle(TDocStd_Document) D;
458 if (!DDocStd::GetDocument(arg[1],D)) return 1;
460 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
462 Handle(TPrsStd_AISViewer) viewer;
463 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
465 Handle(TPrsStd_AISPresentation) prs;
466 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
468 prs->SetMaterial((Graphic3d_NameOfMaterial)atoi(arg[3]));
469 TPrsStd_AISViewer::Update(L);
472 if (prs->HasOwnMaterial()){
473 di << "Material = " << prs->Material() << "\n";
477 di << "DPrsStd_AISMaterial: Warning : Material wasn't set" << "\n";
484 di << "DPrsStd_AISMaterial : Error" << "\n";
488 //=======================================================================
489 //function : DPrsStd_AISDefaultMaterial
490 //purpose : AISDefaultMaterial (DOC,entry)
491 //=======================================================================
493 static Standard_Integer DPrsStd_AISDefaultMaterial (Draw_Interpretor& di,
498 Handle(TDocStd_Document) D;
499 if (!DDocStd::GetDocument(arg[1],D)) return 1;
501 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
503 Handle(TPrsStd_AISViewer) viewer;
504 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
506 Handle(TPrsStd_AISPresentation) prs;
507 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
508 prs->UnsetMaterial();
509 TPrsStd_AISViewer::Update(L);
513 di << "DPrsStd_AISDefaultMaterial : Error" << "\n";
517 //=======================================================================
518 //function : DPrsStd_AISHasOwnColor
519 //purpose : AISHasOwnColor (DOC,entry)
521 //=======================================================================
523 static Standard_Integer DPrsStd_AISHasOwnColor (Draw_Interpretor& di,
529 di << "DPrsStd_AISHasOwnColor : Warning : too many arguments" << "\n";
531 Handle(TDocStd_Document) D;
532 if (!DDocStd::GetDocument(arg[1],D)) return 1;
534 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
536 Handle(TPrsStd_AISViewer) viewer;
537 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
539 Handle(TPrsStd_AISPresentation) prs;
540 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
541 di<<Standard_Integer(prs->HasOwnColor());
546 di << "DPrsStd_AISHasOwnColor : Error" << "\n";
551 //=======================================================================
552 //function : DPrsStd_AISHasOwnMaterial
553 //purpose : AISHasOwnMaterial (DOC,entry)
555 //=======================================================================
557 static Standard_Integer DPrsStd_AISHasOwnMaterial (Draw_Interpretor& di,
563 di << "DPrsStd_AISHasOwnMaterial : Warning : too many arguments" << "\n";
565 Handle(TDocStd_Document) D;
566 if (!DDocStd::GetDocument(arg[1],D)) return 1;
568 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
570 Handle(TPrsStd_AISViewer) viewer;
571 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
573 Handle(TPrsStd_AISPresentation) prs;
574 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
575 di<<Standard_Integer(prs->HasOwnMaterial());
580 di << "DPrsStd_AISHasOwnMaterial : Error" << "\n";
585 //=======================================================================
586 //function : DPrsStd_AISHasOwnTransparency
587 //purpose : AISHasOwnColor (DOC,entry)
589 //=======================================================================
591 static Standard_Integer DPrsStd_AISHasOwnTransparency (Draw_Interpretor& di,
597 di << "DPrsStd_AISHasOwnTransparency : Warning : too many arguments" << "\n";
599 Handle(TDocStd_Document) D;
600 if (!DDocStd::GetDocument(arg[1],D)) return 1;
602 if (!DDF::FindLabel(D->GetData(),arg[2],L)) return 1;
604 Handle(TPrsStd_AISViewer) viewer;
605 if( !TPrsStd_AISViewer::Find(L, viewer) ) return 1;
607 Handle(TPrsStd_AISPresentation) prs;
608 if(L.FindAttribute( TPrsStd_AISPresentation::GetID(), prs) ) {
609 di<<Standard_Integer(prs->HasOwnTransparency());
614 di << "DPrsStd_AISHasOwnTransparency : Error" << "\n";
619 //=======================================================================
620 //function : AISPresentationCommands
622 //=======================================================================
625 void DPrsStd::AISPresentationCommands (Draw_Interpretor& theCommands)
627 static Standard_Boolean done = Standard_False;
629 done = Standard_True;
630 const char* g = "DPrsStd : standard presentation commands" ;
632 // standard commands working on AISPresentation
634 theCommands.Add ("AISDisplay",
635 "AISDisplay (DOC, entry, [not_update])",
636 __FILE__, DPrsStd_AISDisplay, g);
638 theCommands.Add ("AISErase",
639 "AISErase (DOC, entry)",
640 __FILE__, DPrsStd_AISErase, g);
642 theCommands.Add ("AISUpdate",
643 "AISUpdate (DOC, entry)",
644 __FILE__, DPrsStd_AISUpdate, g);
646 theCommands.Add ("AISSet",
647 "AISSet (DOC, entry, ID)",
648 __FILE__, DPrsStd_AISSet, g);
650 theCommands.Add ("AISDriver",
651 "AISDriver (DOC, entry, [ID]) - returns DriverGUID stored in attribute or sets new one",
652 __FILE__, DPrsStd_AISDriver, g);
654 theCommands.Add ("AISUnset",
655 "AISUnset (DOC, entry)",
656 __FILE__, DPrsStd_AISUnset, g);
658 theCommands.Add ("AISTransparency",
659 "AISTransparency (DOC, entry, [real])",
660 __FILE__, DPrsStd_AISTransparency, g);
662 theCommands.Add ("AISDefaultTransparency",
663 "AISDefaultTransparency (DOC, entry)",
664 __FILE__, DPrsStd_AISDefaultTransparency, g);
666 theCommands.Add ("AISHasOwnTransparency",
667 "AISHasOwnTransparency (DOC, entry) | AISHasOwnTransparency return Boolean",
668 __FILE__, DPrsStd_AISHasOwnTransparency, g);
670 theCommands.Add ("AISDefaultColor",
671 "AISDefaultColor (DOC, entry)",
672 __FILE__, DPrsStd_AISDefaultColor, g);
674 theCommands.Add ("AISColor",
675 "AISColor (DOC, entry, [color])",
676 __FILE__, DPrsStd_AISColor, g);
678 theCommands.Add ("AISHasOwnColor",
679 "AISHasOwnColor (DOC, entry) | AISHasOwnColor return Boolean",
680 __FILE__, DPrsStd_AISHasOwnColor, g);
682 theCommands.Add ("AISMaterial",
683 "AISMaterial (DOC, entry, [material])",
684 __FILE__, DPrsStd_AISMaterial, g);
686 theCommands.Add ("AISDefaultMaterial",
687 "AISDefaultMaterial (DOC, entry)",
688 __FILE__, DPrsStd_AISDefaultMaterial, g);
690 theCommands.Add ("AISHasOwnMaterial",
691 "AISHasOwnMaterial (DOC, entry) | AISHasOwnMaterial return Boolean",
692 __FILE__, DPrsStd_AISHasOwnMaterial, g);
694 theCommands.Add ("AISRemove",
695 "AISRemove (DOC, entry)",
696 __FILE__, DPrsStd_AISRemove, g);