0028095: Draw Harness, ViewerTest - use RGBA format instead of BGRA within vreadpixel
[occt.git] / src / ViewerTest / ViewerTest.cxx
CommitLineData
b311480e 1// Created on: 1997-07-23
2// Created by: Henri JEANNIN
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
7fd59977 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
17// Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
7fd59977 18// Modified by Robert Coublanc [nov 16-17-18 1998]
19// -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20// ViewerTest_ObjectCommands.cxx
21// ViewerTest_RelationCommands.cxx
22// -add Functions and commands for interactive selection of shapes and objects
23// in AIS Viewers. (PickShape(s), PickObject(s),
24
25#include <Standard_Stream.hxx>
26
27#include <ViewerTest.hxx>
189f85a3 28#include <ViewerTest_CmdParser.hxx>
4e18052b 29
7fd59977 30#include <TopLoc_Location.hxx>
31#include <TopTools_HArray1OfShape.hxx>
32#include <TColStd_HArray1OfTransient.hxx>
b6d587e3 33#include <TColStd_SequenceOfAsciiString.hxx>
900f7229 34#include <TColStd_HSequenceOfAsciiString.hxx>
b6d587e3 35#include <TColStd_MapOfTransient.hxx>
7fd59977 36#include <OSD_Timer.hxx>
37#include <Geom_Axis2Placement.hxx>
38#include <Geom_Axis1Placement.hxx>
39#include <gp_Trsf.hxx>
40#include <TopExp_Explorer.hxx>
41#include <BRepAdaptor_Curve.hxx>
42#include <StdSelect_ShapeTypeFilter.hxx>
43#include <AIS.hxx>
ad3217cd 44#include <AIS_ColoredShape.hxx>
7fd59977 45#include <AIS_InteractiveObject.hxx>
46#include <AIS_Trihedron.hxx>
47#include <AIS_Axis.hxx>
48#include <AIS_Relation.hxx>
49#include <AIS_TypeFilter.hxx>
50#include <AIS_SignatureFilter.hxx>
cb78155f 51#include <AIS_LocalContext.hxx>
7fd59977 52#include <AIS_ListOfInteractive.hxx>
53#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 54#include <Aspect_InteriorStyle.hxx>
34db9c00 55#include <Aspect_Window.hxx>
99c56d44 56#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 57#include <Graphic3d_AspectLine3d.hxx>
a1954302 58#include <Graphic3d_CStructure.hxx>
392ac980 59#include <Graphic3d_TextureRoot.hxx>
692613e5 60#include <Image_AlienPixMap.hxx>
6262338c 61#include <Prs3d_Drawer.hxx>
99c56d44 62#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 63#include <Prs3d_IsoAspect.hxx>
6262338c 64#include <Prs3d_PointAspect.hxx>
8e7c8ccf 65#include <Select3D_SensitiveWire.hxx>
8b9a309b 66#include <Select3D_SensitivePrimitiveArray.hxx>
8e7c8ccf 67#include <SelectMgr_EntityOwner.hxx>
68#include <StdSelect_BRepOwner.hxx>
69#include <StdSelect_ViewerSelector3d.hxx>
cb78155f 70#include <TopTools_MapOfShape.hxx>
4e18052b 71#include <ViewerTest_AutoUpdater.hxx>
7fd59977 72
7fd59977 73#include <stdio.h>
7fd59977 74
75#include <Draw_Interpretor.hxx>
76#include <TCollection_AsciiString.hxx>
77#include <Draw_PluginMacro.hxx>
7fd59977 78
7fd59977 79extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
80
7fd59977 81#include <Quantity_Color.hxx>
82#include <Quantity_NameOfColor.hxx>
83
84#include <Graphic3d_NameOfMaterial.hxx>
85
6262338c 86#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
87#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
88#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
7fd59977 89
792c785c 90//=======================================================================
91//function : GetColorFromName
92//purpose : get the Quantity_NameOfColor from a string
93//=======================================================================
7fd59977 94
792c785c 95Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
96{
8316c618 97 Quantity_NameOfColor aColor = DEFAULT_COLOR;
98 Quantity_Color::ColorFromName (theName, aColor);
99 return aColor;
7fd59977 100}
101
536d98e2 102//=======================================================================
103//function : ParseColor
104//purpose :
105//=======================================================================
106
107Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
108 const char** theArgVec,
109 Quantity_Color& theColor)
110{
111 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
112 if (theArgNb >= 1
113 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
114 {
115 theColor = aColor;
116 return 1;
117 }
118 else if (theArgNb >= 3)
119 {
120 const TCollection_AsciiString anRgbStr[3] =
121 {
122 theArgVec[0],
123 theArgVec[1],
124 theArgVec[2]
125 };
126 if (!anRgbStr[0].IsRealValue()
127 || !anRgbStr[1].IsRealValue()
128 || !anRgbStr[2].IsRealValue())
129 {
130 return 0;
131 }
132
133 Graphic3d_Vec4d anRgb;
134 anRgb.x() = anRgbStr[0].RealValue();
135 anRgb.y() = anRgbStr[1].RealValue();
136 anRgb.z() = anRgbStr[2].RealValue();
137 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
138 || anRgb.y() < 0.0 || anRgb.y() > 1.0
139 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
140 {
141 std::cout << "Error: RGB color values should be within range 0..1!\n";
142 return 0;
143 }
144
145 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
146 return 3;
147 }
148
149 return 0;
150}
151
a5565a3c 152//=======================================================================
153//function : ParseOnOff
154//purpose :
155//=======================================================================
156Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
157 Standard_Boolean& theIsOn)
158{
159 TCollection_AsciiString aFlag(theArg);
160 aFlag.LowerCase();
161 if (aFlag == "on"
162 || aFlag == "1")
163 {
164 theIsOn = Standard_True;
165 return Standard_True;
166 }
167 else if (aFlag == "off"
168 || aFlag == "0")
169 {
170 theIsOn = Standard_False;
171 return Standard_True;
172 }
173 return Standard_False;
174}
175
7fd59977 176//=======================================================================
177//function : GetTypeNames
178//purpose :
179//=======================================================================
180static const char** GetTypeNames()
181{
182 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
183 "Shape","ConnectedShape","MultiConn.Shape",
184 "ConnectedInter.","MultiConn.",
185 "Constraint","Dimension"};
186 static const char** ThePointer = names;
187 return ThePointer;
188}
189
190//=======================================================================
191//function : GetTypeAndSignfromString
192//purpose :
193//=======================================================================
194void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
195{
196 const char ** thefullnames = GetTypeNames();
197 Standard_Integer index(-1);
198
199 for(Standard_Integer i=0;i<=13 && index==-1;i++)
200 if(!strcasecmp(name,thefullnames[i]))
201 index = i;
202
203 if(index ==-1){
204 TheType = AIS_KOI_None;
205 TheSign = -1;
206 return;
207 }
208
209 if(index<=6){
210 TheType = AIS_KOI_Datum;
211 TheSign = index+1;
212 }
213 else if (index <=9){
214 TheType = AIS_KOI_Shape;
215 TheSign = index-7;
216 }
217 else if(index<=11){
218 TheType = AIS_KOI_Object;
219 TheSign = index-10;
220 }
221 else{
222 TheType = AIS_KOI_Relation;
223 TheSign = index-12;
224 }
225
226}
227
228
229
230#include <string.h>
231#include <Draw_Interpretor.hxx>
232#include <Draw.hxx>
233#include <Draw_Appli.hxx>
234#include <DBRep.hxx>
235
236
237#include <TCollection_AsciiString.hxx>
238#include <V3d_Viewer.hxx>
239#include <V3d_View.hxx>
240#include <V3d.hxx>
241
242#include <AIS_InteractiveContext.hxx>
243#include <AIS_Shape.hxx>
244#include <AIS_TexturedShape.hxx>
245#include <AIS_DisplayMode.hxx>
246#include <TColStd_MapOfInteger.hxx>
247#include <AIS_MapOfInteractive.hxx>
248#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
249#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
250#include <ViewerTest_EventManager.hxx>
251
252#include <TopoDS_Solid.hxx>
253#include <BRepTools.hxx>
254#include <BRep_Builder.hxx>
255#include <TopAbs_ShapeEnum.hxx>
256
257#include <TopoDS.hxx>
258#include <BRep_Tool.hxx>
259
260
261#include <Draw_Window.hxx>
262#include <AIS_ListIteratorOfListOfInteractive.hxx>
263#include <AIS_ListOfInteractive.hxx>
264#include <AIS_DisplayMode.hxx>
265#include <TopTools_ListOfShape.hxx>
266#include <BRepOffsetAPI_MakeThickSolid.hxx>
267#include <BRepOffset.hxx>
268
7fd59977 269//==============================================================================
270// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
271//==============================================================================
272Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
273 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
274 return TheMap;
275}
276
29e2c6d2 277//=======================================================================
278//function : Display
279//purpose :
280//=======================================================================
281Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
282 const Handle(AIS_InteractiveObject)& theObject,
283 const Standard_Boolean theToUpdate,
284 const Standard_Boolean theReplaceIfExists)
9558a876
A
285{
286 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29e2c6d2 287 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
288 if (aCtx.IsNull())
9558a876 289 {
29e2c6d2 290 std::cout << "Error: AIS context is not available.\n";
9558a876
A
291 return Standard_False;
292 }
293
294 if (aMap.IsBound2 (theName))
295 {
296 if (!theReplaceIfExists)
297 {
29e2c6d2 298 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
9558a876
A
299 << "Please use another name.\n";
300 return Standard_False;
301 }
302
29e2c6d2 303 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
9558a876 304 if (!anOldObj.IsNull())
29e2c6d2 305 {
1beb58d7 306 aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate);
29e2c6d2 307 }
9558a876
A
308 aMap.UnBind2 (theName);
309 }
310
29e2c6d2 311 if (theObject.IsNull())
208e6839 312 {
29e2c6d2 313 // object with specified name has been already unbound
208e6839 314 return Standard_True;
315 }
316
29e2c6d2 317 // unbind AIS object if it was bound with another name
318 aMap.UnBind1 (theObject);
9558a876
A
319
320 // can be registered without rebinding
29e2c6d2 321 aMap.Bind (theObject, theName);
322 aCtx->Display (theObject, theToUpdate);
9558a876
A
323 return Standard_True;
324}
325
29e2c6d2 326//! Alias for ViewerTest::Display(), compatibility with old code.
327Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
328 const Handle(AIS_InteractiveObject)& theObject,
329 Standard_Boolean theReplaceIfExists = Standard_True)
330{
331 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
332}
333
7fd59977 334static TColStd_MapOfInteger theactivatedmodes(8);
335static TColStd_ListOfTransient theEventMgrs;
336
d09dda09 337static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
7fd59977 338 const Handle(AIS_InteractiveContext)& Ctx)
339{
340 theEventMgrs.Clear();
341 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
342}
343
24de79c3 344static Handle(V3d_View)& a3DView()
345{
7fd59977 346 static Handle(V3d_View) Viou;
347 return Viou;
348}
349
24de79c3 350
7fd59977 351Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
352 static Handle(AIS_InteractiveContext) aContext;
353 return aContext;
354}
355
24de79c3 356const Handle(V3d_View)& ViewerTest::CurrentView()
7fd59977 357{
358 return a3DView();
359}
360void ViewerTest::CurrentView(const Handle(V3d_View)& V)
361{
362 a3DView() = V;
363}
364
24de79c3 365const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
7fd59977 366{
367 return TheAISContext();
368}
369
370void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
371{
372 TheAISContext() = aCtx;
373 ViewerTest::ResetEventManager();
374}
375
376Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
377{
4952a30a 378 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 379}
380
381Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
382{
4952a30a 383 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 384}
385
386
387void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
388 theEventMgrs.Prepend(EM);
389}
390
391void ViewerTest::UnsetEventManager()
392{
393 theEventMgrs.RemoveFirst();
394}
395
396
397void ViewerTest::ResetEventManager()
398{
d09dda09 399 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 400 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
401}
402
403Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
404{
405 Handle(ViewerTest_EventManager) EM;
406 if(theEventMgrs.IsEmpty()) return EM;
407 Handle(Standard_Transient) Tr = theEventMgrs.First();
c5f3a425 408 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
7fd59977 409 return EM;
410}
411
7fd59977 412//=======================================================================
34db9c00 413//function : Get Context and active view
7fd59977 414//purpose :
415//=======================================================================
34db9c00 416static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
417 Handle(V3d_View)& theView)
7fd59977 418{
34db9c00 419 theCtx = ViewerTest::GetAISContext();
420 theView = ViewerTest::CurrentView();
421 if (theCtx.IsNull()
422 || theView.IsNull())
7fd59977 423 {
34db9c00 424 std::cout << "Error: cannot find an active view!\n";
425 return Standard_False;
7fd59977 426 }
34db9c00 427 return Standard_True;
7fd59977 428}
429
7fd59977 430//==============================================================================
431//function : GetShapeFromName
432//purpose : Compute an Shape from a draw variable or a file name
433//==============================================================================
434
435static TopoDS_Shape GetShapeFromName(const char* name)
436{
437 TopoDS_Shape S = DBRep::Get(name);
438
439 if ( S.IsNull() ) {
440 BRep_Builder aBuilder;
441 BRepTools::Read( S, name, aBuilder);
442 }
443
444 return S;
445}
4e18e72a 446
7fd59977 447//==============================================================================
448//function : GetAISShapeFromName
449//purpose : Compute an AIS_Shape from a draw variable or a file name
450//==============================================================================
451Handle(AIS_Shape) GetAISShapeFromName(const char* name)
452{
453 Handle(AIS_Shape) retsh;
454
455 if(GetMapOfAIS().IsBound2(name)){
456 const Handle(AIS_InteractiveObject) IO =
457 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
458 if (!IO.IsNull()) {
eafb234b 459 if(IO->Type()==AIS_KOI_Shape) {
7fd59977 460 if(IO->Signature()==0){
c5f3a425 461 retsh = Handle(AIS_Shape)::DownCast (IO);
7fd59977 462 }
463 else
464 cout << "an Object which is not an AIS_Shape "
465 "already has this name!!!"<<endl;
eafb234b 466 }
7fd59977 467 }
468 return retsh;
469 }
470
471
472 TopoDS_Shape S = GetShapeFromName(name);
473 if ( !S.IsNull() ) {
474 retsh = new AIS_Shape(S);
475 }
476 return retsh;
477}
478
479
480//==============================================================================
481//function : Clear
482//purpose : Remove all the object from the viewer
483//==============================================================================
484void ViewerTest::Clear()
485{
486 if ( !a3DView().IsNull() ) {
487 if (TheAISContext()->HasOpenedContext())
488 TheAISContext()->CloseLocalContext();
489 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
490 while ( it.More() ) {
491 cout << "Remove " << it.Key2() << endl;
d09dda09 492 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
493 TheAISContext()->Remove(anObj,Standard_False);
7fd59977 494 it.Next();
495 }
f751596e 496 TheAISContext()->RebuildSelectionStructs();
7fd59977 497 TheAISContext()->UpdateCurrentViewer();
7fd59977 498 GetMapOfAIS().Clear();
499 }
500}
501
502//==============================================================================
503//function : StandardModesActivation
504//purpose : Activate a selection mode, vertex, edge, wire ..., in a local
505// Context
506//==============================================================================
507void ViewerTest::StandardModeActivation(const Standard_Integer mode )
508{
509 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
510 if(mode==0) {
511 if (TheAISContext()->HasOpenedContext())
512 aContext->CloseLocalContext();
513 } else {
514
515 if(!aContext->HasOpenedContext()) {
516 // To unhilight the preselected object
c3282ec1 517 aContext->UnhilightSelected(Standard_False);
7fd59977 518 // Open a local Context in order to be able to select subshape from
519 // the selected shape if any or for all if there is no selection
c3282ec1 520 if (!aContext->FirstSelectedObject().IsNull()){
7fd59977 521 aContext->OpenLocalContext(Standard_False);
522
c3282ec1 523 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
524 aContext->Load( aContext->SelectedInteractive(),-1,Standard_True);
7fd59977 525 }
526 }
527 else
528 aContext->OpenLocalContext();
529 }
530
531 const char *cmode="???";
532
533 switch (mode) {
534 case 0: cmode = "Shape"; break;
535 case 1: cmode = "Vertex"; break;
536 case 2: cmode = "Edge"; break;
537 case 3: cmode = "Wire"; break;
538 case 4: cmode = "Face"; break;
539 case 5: cmode = "Shell"; break;
540 case 6: cmode = "Solid"; break;
4754e164 541 case 7: cmode = "Compsolid"; break;
542 case 8: cmode = "Compound"; break;
7fd59977 543 }
544
545 if(theactivatedmodes.Contains(mode))
546 { // Desactivate
547 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
548 theactivatedmodes.Remove(mode);
549 cout<<"Mode "<< cmode <<" OFF"<<endl;
550 }
551 else
552 { // Activate
553 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
554 theactivatedmodes.Add(mode);
555 cout<<"Mode "<< cmode << " ON" << endl;
556 }
557 }
558}
559
1c88cbaf 560//==============================================================================
561//function : CopyIsoAspect
562//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
563//==============================================================================
564static Handle(Prs3d_IsoAspect) CopyIsoAspect
565 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
566 const Standard_Integer theNbIsos)
567{
b6472664 568 Quantity_Color aColor = theIsoAspect->Aspect()->Color();
569 Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type();
570 Standard_Real aWidth = theIsoAspect->Aspect()->Width();
1c88cbaf 571
572 Handle(Prs3d_IsoAspect) aResult =
573 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
574
575 return aResult;
576}
577
578//==============================================================================
579//function : visos
580//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
581//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
582//==============================================================================
583static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
584{
585 if (TheAISContext().IsNull()) {
586 di << argv[0] << " Call 'vinit' before!\n";
587 return 1;
588 }
589
590 if (argc <= 1) {
591 di << "Current number of isos : " <<
592 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
593 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
594 di << "IsoOnPlane mode is " <<
595 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
5ad8c033 596 di << "IsoOnTriangulation mode is " <<
597 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
1c88cbaf 598 return 0;
599 }
600
601 Standard_Integer aLastInd = argc - 1;
602 Standard_Boolean isChanged = Standard_False;
1d47d8d0 603 Standard_Integer aNbUIsos = 0;
604 Standard_Integer aNbVIsos = 0;
1c88cbaf 605
606 if (aLastInd >= 3) {
607 Standard_Boolean isIsoOnPlane = Standard_False;
608
609 if (strcmp(argv[aLastInd], "1") == 0) {
610 isIsoOnPlane = Standard_True;
611 isChanged = Standard_True;
612 } else if (strcmp(argv[aLastInd], "0") == 0) {
613 isIsoOnPlane = Standard_False;
614 isChanged = Standard_True;
615 }
616
617 if (isChanged) {
618 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
619 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
620 aLastInd -= 3;
621
622 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
623 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
624
625 TheAISContext()->IsoOnPlane(isIsoOnPlane);
626
627 if (aLastInd == 0) {
628 // If there are no shapes provided set the default numbers.
629 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
630 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
631 }
632 }
633 }
634
635 Standard_Integer i;
636
637 for (i = 1; i <= aLastInd; i++) {
638 TCollection_AsciiString name(argv[i]);
639 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
640
641 if (IsBound) {
642 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
643 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
644 const Handle(AIS_InteractiveObject) aShape =
645 Handle(AIS_InteractiveObject)::DownCast (anObj);
6262338c 646 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
1c88cbaf 647 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
648 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
649
650 if (isChanged) {
651 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
652 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
653 TheAISContext()->SetLocalAttributes
654 (aShape, CurDrawer, Standard_False);
655 TheAISContext()->Redisplay(aShape);
656 } else {
657 di << "Number of isos for " << argv[i] << " : "
658 << aUIso->Number() << " " << aVIso->Number() << "\n";
659 }
660 } else {
661 di << argv[i] << ": Not an AIS interactive object!\n";
662 }
663 } else {
664 di << argv[i] << ": Use 'vdisplay' before\n";
665 }
666 }
667
668 if (isChanged) {
669 TheAISContext()->UpdateCurrentViewer();
670 }
671
672 return 0;
673}
674
34db9c00 675static Standard_Integer VDispSensi (Draw_Interpretor& ,
676 Standard_Integer theArgNb,
677 Standard_CString* )
7fd59977 678{
34db9c00 679 if (theArgNb > 1)
680 {
681 std::cout << "Error: wrong syntax!\n";
682 return 1;
683 }
684
685 Handle(AIS_InteractiveContext) aCtx;
686 Handle(V3d_View) aView;
687 if (!getCtxAndView (aCtx, aView))
688 {
689 return 1;
690 }
691
692 aCtx->DisplayActiveSensitive (aView);
7fd59977 693 return 0;
694
695}
34db9c00 696
697static Standard_Integer VClearSensi (Draw_Interpretor& ,
698 Standard_Integer theArgNb,
699 Standard_CString* )
7fd59977 700{
34db9c00 701 if (theArgNb > 1)
702 {
703 std::cout << "Error: wrong syntax!\n";
704 return 1;
705 }
706
707 Handle(AIS_InteractiveContext) aCtx;
708 Handle(V3d_View) aView;
709 if (!getCtxAndView (aCtx, aView))
710 {
711 return 1;
712 }
713 aCtx->ClearActiveSensitive (aView);
7fd59977 714 return 0;
715}
716
717//==============================================================================
519d35d8 718//function : VDir
7fd59977 719//purpose : To list the displayed object with their attributes
7fd59977 720//==============================================================================
519d35d8 721static int VDir (Draw_Interpretor& theDI,
722 Standard_Integer ,
723 const char** )
724{
725 if (!a3DView().IsNull())
726 {
727 return 0;
7fd59977 728 }
729
519d35d8 730 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
731 anIter.More(); anIter.Next())
732 {
733 theDI << "\t" << anIter.Key2().ToCString() << "\n";
734 }
7fd59977 735 return 0;
736}
737
f978241f 738//! Auxiliary enumeration
739enum ViewerTest_StereoPair
740{
741 ViewerTest_SP_Single,
742 ViewerTest_SP_SideBySide,
743 ViewerTest_SP_OverUnder
744};
745
7fd59977 746//==============================================================================
747//function : VDump
748//purpose : To dump the active view snapshot to image file
7fd59977 749//==============================================================================
34db9c00 750static Standard_Integer VDump (Draw_Interpretor& theDI,
751 Standard_Integer theArgNb,
752 Standard_CString* theArgVec)
7fd59977 753{
34db9c00 754 if (theArgNb < 2)
7fd59977 755 {
34db9c00 756 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
7fd59977 757 return 1;
758 }
759
34db9c00 760 Standard_Integer anArgIter = 1;
761 Standard_CString aFilePath = theArgVec[anArgIter++];
f978241f 762 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
3bffef55 763 V3d_ImageDumpOptions aParams;
764 aParams.BufferType = Graphic3d_BT_RGB;
765 aParams.StereoOptions = V3d_SDO_MONO;
34db9c00 766 for (; anArgIter < theArgNb; ++anArgIter)
7fd59977 767 {
34db9c00 768 TCollection_AsciiString anArg (theArgVec[anArgIter]);
769 anArg.LowerCase();
f978241f 770 if (anArg == "-buffer")
7fd59977 771 {
f978241f 772 if (++anArgIter >= theArgNb)
773 {
774 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
775 return 1;
776 }
777
778 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
779 aBufArg.LowerCase();
780 if (aBufArg == "rgba")
781 {
3bffef55 782 aParams.BufferType = Graphic3d_BT_RGBA;
f978241f 783 }
784 else if (aBufArg == "rgb")
785 {
3bffef55 786 aParams.BufferType = Graphic3d_BT_RGB;
f978241f 787 }
788 else if (aBufArg == "depth")
789 {
3bffef55 790 aParams.BufferType = Graphic3d_BT_Depth;
f978241f 791 }
792 else
793 {
794 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
795 return 1;
796 }
7fd59977 797 }
f978241f 798 else if (anArg == "-stereo")
7fd59977 799 {
f978241f 800 if (++anArgIter >= theArgNb)
801 {
802 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
803 return 1;
804 }
805
806 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
807 aStereoArg.LowerCase();
808 if (aStereoArg == "l"
809 || aStereoArg == "left")
810 {
3bffef55 811 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
f978241f 812 }
813 else if (aStereoArg == "r"
814 || aStereoArg == "right")
815 {
3bffef55 816 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
f978241f 817 }
818 else if (aStereoArg == "mono")
819 {
3bffef55 820 aParams.StereoOptions = V3d_SDO_MONO;
f978241f 821 }
822 else if (aStereoArg == "blended"
823 || aStereoArg == "blend"
824 || aStereoArg == "stereo")
825 {
3bffef55 826 aParams.StereoOptions = V3d_SDO_BLENDED;
f978241f 827 }
828 else if (aStereoArg == "sbs"
829 || aStereoArg == "sidebyside")
830 {
831 aStereoPair = ViewerTest_SP_SideBySide;
832 }
833 else if (aStereoArg == "ou"
834 || aStereoArg == "overunder")
835 {
836 aStereoPair = ViewerTest_SP_OverUnder;
837 }
838 else
839 {
840 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
841 return 1;
842 }
7fd59977 843 }
f978241f 844 else if (anArg == "-rgba"
845 || anArg == "rgba")
34db9c00 846 {
3bffef55 847 aParams.BufferType = Graphic3d_BT_RGBA;
34db9c00 848 }
f978241f 849 else if (anArg == "-rgb"
850 || anArg == "rgb")
34db9c00 851 {
3bffef55 852 aParams.BufferType = Graphic3d_BT_RGB;
34db9c00 853 }
f978241f 854 else if (anArg == "-depth"
855 || anArg == "depth")
34db9c00 856 {
3bffef55 857 aParams.BufferType = Graphic3d_BT_Depth;
34db9c00 858 }
f978241f 859 else if (anArg == "-width"
860 || anArg == "width"
861 || anArg == "sizex")
34db9c00 862 {
3bffef55 863 if (aParams.Width != 0)
34db9c00 864 {
865 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
866 return 1;
867 }
868 else if (++anArgIter >= theArgNb)
869 {
870 std::cout << "Error: integer value is expected right after 'width'\n";
871 return 1;
872 }
3bffef55 873 aParams.Width = Draw::Atoi (theArgVec[anArgIter]);
34db9c00 874 }
f978241f 875 else if (anArg == "-height"
876 || anArg == "height"
877 || anArg == "-sizey")
34db9c00 878 {
3bffef55 879 if (aParams.Height != 0)
34db9c00 880 {
881 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
882 return 1;
883 }
34db9c00 884 else if (++anArgIter >= theArgNb)
885 {
f978241f 886 std::cout << "Error: integer value is expected right after 'height'\n";
34db9c00 887 return 1;
888 }
3bffef55 889 aParams.Height = Draw::Atoi (theArgVec[anArgIter]);
890 }
891 else if (anArg == "-tile"
892 || anArg == "-tilesize")
893 {
894 if (++anArgIter >= theArgNb)
895 {
896 std::cout << "Error: integer value is expected right after 'tileSize'\n";
897 return 1;
898 }
899 aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]);
34db9c00 900 }
901 else
902 {
903 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
904 return 1;
905 }
7fd59977 906 }
3bffef55 907 if ((aParams.Width <= 0 && aParams.Height > 0)
908 || (aParams.Width > 0 && aParams.Height <= 0))
7fd59977 909 {
3bffef55 910 std::cout << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect\n";
85e096c3 911 return 1;
912 }
913
34db9c00 914 Handle(V3d_View) aView = ViewerTest::CurrentView();
915 if (aView.IsNull())
85e096c3 916 {
34db9c00 917 std::cout << "Error: cannot find an active view!\n";
918 return 1;
7fd59977 919 }
85e096c3 920
3bffef55 921 if (aParams.Width <= 0 || aParams.Height <= 0)
b5ac8292 922 {
3bffef55 923 aView->Window()->Size (aParams.Width, aParams.Height);
f978241f 924 }
925
926 Image_AlienPixMap aPixMap;
f978241f 927 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
3bffef55 928 switch (aParams.BufferType)
f978241f 929 {
f9f740d6 930 case Graphic3d_BT_RGB: aFormat = Image_PixMap::ImgRGB; break;
931 case Graphic3d_BT_RGBA: aFormat = Image_PixMap::ImgRGBA; break;
f978241f 932 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
933 }
934
935 switch (aStereoPair)
936 {
937 case ViewerTest_SP_Single:
b5ac8292 938 {
3bffef55 939 if (!aView->ToPixMap (aPixMap, aParams))
f978241f 940 {
941 theDI << "Fail: view dump failed!\n";
942 return 0;
943 }
3bffef55 944 else if (aPixMap.SizeX() != Standard_Size(aParams.Width)
945 || aPixMap.SizeY() != Standard_Size(aParams.Height))
f978241f 946 {
947 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
3bffef55 948 << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n";
f978241f 949 }
950 break;
b5ac8292 951 }
f978241f 952 case ViewerTest_SP_SideBySide:
b5ac8292 953 {
3bffef55 954 if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height))
f978241f 955 {
956 theDI << "Fail: not enough memory for image allocation!\n";
957 return 0;
958 }
959
960 Image_PixMap aPixMapL, aPixMapR;
961 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
3bffef55 962 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
963 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width,
964 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
965
966 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
967 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
968 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
969 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
970 if (!isOk)
34db9c00 971 {
972 theDI << "Fail: view dump failed!\n";
f978241f 973 return 0;
34db9c00 974 }
f978241f 975 break;
b5ac8292 976 }
f978241f 977 case ViewerTest_SP_OverUnder:
978 {
3bffef55 979 if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2))
f978241f 980 {
981 theDI << "Fail: not enough memory for image allocation!\n";
982 return 0;
983 }
b5ac8292 984
f978241f 985 Image_PixMap aPixMapL, aPixMapR;
f9f740d6 986 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
3bffef55 987 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
f9f740d6 988 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height,
3bffef55 989 aParams.Width, aParams.Height, aPixMap.SizeRowBytes());
990
991 aParams.StereoOptions = V3d_SDO_LEFT_EYE;
992 Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams);
993 aParams.StereoOptions = V3d_SDO_RIGHT_EYE;
994 isOk = isOk && aView->ToPixMap (aPixMapR, aParams);
995 if (!isOk)
f978241f 996 {
997 theDI << "Fail: view dump failed!\n";
998 return 0;
999 }
1000 break;
1001 }
7fd59977 1002 }
85e096c3 1003
34db9c00 1004 if (!aPixMap.Save (aFilePath))
85e096c3 1005 {
34db9c00 1006 theDI << "Fail: image can not be saved!\n";
85e096c3 1007 }
1008 return 0;
7fd59977 1009}
1010
dde68833 1011enum TypeOfDispOperation
7fd59977 1012{
dde68833 1013 TypeOfDispOperation_SetDispMode,
1014 TypeOfDispOperation_UnsetDispMode
1015};
7fd59977 1016
dde68833 1017//! Displays,Erase...
1018static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs,
1019 const Standard_Integer theMode,
1020 const TypeOfDispOperation theType,
1021 const Standard_Boolean theToUpdate)
1022{
1023 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1024 switch (theType)
1025 {
1026 case TypeOfDispOperation_SetDispMode:
1027 {
1028 if (!thePrs.IsNull())
1029 {
1030 aCtx->SetDisplayMode (thePrs, theMode, theToUpdate);
1031 }
1032 else
1033 {
1034 aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate);
1035 }
1036 break;
1037 }
1038 case TypeOfDispOperation_UnsetDispMode:
1039 {
1040 if (!thePrs.IsNull())
1041 {
1042 aCtx->UnsetDisplayMode (thePrs, theToUpdate);
1043 }
1044 else
1045 {
1046 aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate);
1047 }
1048 break;
1049 }
7fd59977 1050 }
7fd59977 1051}
1052
1053//=======================================================================
1054//function :
1055//purpose :
1056//=======================================================================
1057static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1058{
dde68833 1059 if (argc < 1
1060 || argc > 3)
1061 {
1062 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 1063 return 1;
dde68833 1064 }
7fd59977 1065
dde68833 1066 TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode"
1067 ? TypeOfDispOperation_UnsetDispMode
1068 : TypeOfDispOperation_SetDispMode;
1069 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1070 if (aType == TypeOfDispOperation_UnsetDispMode)
1071 {
1072 if (argc == 1)
1073 {
1074 if (aCtx->NbSelected() == 0)
1075 {
1076 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1077 }
1078 else
1079 {
1080 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1081 {
1082 VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False);
1083 }
7fd59977 1084 }
dde68833 1085 aCtx->UpdateCurrentViewer();
7fd59977 1086 }
dde68833 1087 else
1088 {
1089 TCollection_AsciiString aName = argv[1];
1090 if (GetMapOfAIS().IsBound2 (aName))
1091 {
1092 Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1093 if (!aPrs.IsNull())
1094 {
1095 VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True);
1096 }
7fd59977 1097 }
1098 }
1099 }
dde68833 1100 else if (argc == 2)
1101 {
1102 Standard_Integer aDispMode = Draw::Atoi (argv[1]);
1103 if (aCtx->NbSelected() == 0
1104 && aType == TypeOfDispOperation_SetDispMode)
1105 {
1106 VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True);
7fd59977 1107 }
dde68833 1108 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
1109 {
1110 VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False);
7fd59977 1111 }
dde68833 1112 aCtx->UpdateCurrentViewer();
7fd59977 1113 }
dde68833 1114 else
1115 {
1116 Handle(AIS_InteractiveObject) aPrs;
1117 TCollection_AsciiString aName (argv[1]);
1118 if (GetMapOfAIS().IsBound2 (aName))
1119 {
1120 aPrs = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
1121 }
1122 if (!aPrs.IsNull())
1123 {
1124 VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True);
1125 }
7fd59977 1126 }
1127 return 0;
1128}
1129
1130
1131//=======================================================================
1132//function :
1133//purpose :
1134//=======================================================================
1135static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1136{
1137 if(argc==1) return 1;
91322f44 1138 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 1139 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1140
c3282ec1 1141 if(argc==2)
1142 {
1143 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1144 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1145 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1146 {
1147 if(On==1)
1148 {
1149 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1150 }
c3282ec1 1151 else
1152 {
1153 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1154 }
1155 }
c3282ec1 1156
7fd59977 1157 Ctx->UpdateCurrentViewer();
1158 }
1159 else {
1160 Handle(AIS_InteractiveObject) IO;
1161 TCollection_AsciiString name = argv[2];
1162 if(GetMapOfAIS().IsBound2(name)){
1163 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
eafb234b 1164 if (!IO.IsNull()) {
7fd59977 1165 if(On==1)
1166 Ctx->SubIntensityOn(IO);
1167 else
1168 Ctx->SubIntensityOff(IO);
eafb234b 1169 }
7fd59977 1170 }
1171 else return 1;
1172 }
1173 return 0;
7fd59977 1174}
7fd59977 1175
ad3217cd 1176//! Auxiliary class to iterate presentations from different collections.
1177class ViewTest_PrsIter
1178{
1179public:
7fd59977 1180
ad3217cd 1181 //! Create and initialize iterator object.
1182 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1183 : mySource (IterSource_All)
1184 {
1185 NCollection_Sequence<TCollection_AsciiString> aNames;
1186 if (!theName.IsEmpty())
1187 aNames.Append (theName);
1188 Init (aNames);
7fd59977 1189 }
ad3217cd 1190
1191 //! Create and initialize iterator object.
1192 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1193 : mySource (IterSource_All)
1194 {
1195 Init (theNames);
7fd59977 1196 }
1197
ad3217cd 1198 //! Initialize the iterator.
1199 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1200 {
1201 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1202 mySeq = theNames;
1203 mySelIter.Nullify();
1204 myCurrent.Nullify();
1205 myCurrentTrs.Nullify();
1206 if (!mySeq.IsEmpty())
1207 {
1208 mySource = IterSource_List;
1209 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
7fd59977 1210 }
c3282ec1 1211 else if (aCtx->NbSelected() > 0)
ad3217cd 1212 {
1213 mySource = IterSource_Selected;
1214 mySelIter = aCtx;
c3282ec1 1215 mySelIter->InitSelected();
ad3217cd 1216 }
1217 else
1218 {
1219 mySource = IterSource_All;
1220 myMapIter.Initialize (GetMapOfAIS());
1221 }
1222 initCurrent();
1223 }
7fd59977 1224
ad3217cd 1225 const TCollection_AsciiString& CurrentName() const
1226 {
1227 return myCurrentName;
1228 }
7fd59977 1229
ad3217cd 1230 const Handle(AIS_InteractiveObject)& Current() const
1231 {
1232 return myCurrent;
1233 }
7fd59977 1234
ad3217cd 1235 const Handle(Standard_Transient)& CurrentTrs() const
1236 {
1237 return myCurrentTrs;
1238 }
1239
1240 //! @return true if iterator points to valid object within collection
1241 Standard_Boolean More() const
1242 {
1243 switch (mySource)
1244 {
1245 case IterSource_All: return myMapIter.More();
1246 case IterSource_List: return mySeqIter.More();
c3282ec1 1247 case IterSource_Selected: return mySelIter->MoreSelected();
ad3217cd 1248 }
1249 return Standard_False;
1250 }
1251
1252 //! Go to the next item.
1253 void Next()
1254 {
1255 myCurrentName.Clear();
1256 myCurrentTrs.Nullify();
1257 myCurrent.Nullify();
1258 switch (mySource)
1259 {
1260 case IterSource_All:
1261 {
1262 myMapIter.Next();
1263 break;
1264 }
1265 case IterSource_List:
1266 {
1267 mySeqIter.Next();
1268 break;
1269 }
1270 case IterSource_Selected:
1271 {
c3282ec1 1272 mySelIter->NextSelected();
ad3217cd 1273 break;
7fd59977 1274 }
1275 }
ad3217cd 1276 initCurrent();
1277 }
7fd59977 1278
ad3217cd 1279private:
7fd59977 1280
ad3217cd 1281 void initCurrent()
1282 {
1283 switch (mySource)
1284 {
1285 case IterSource_All:
7fd59977 1286 {
ad3217cd 1287 if (myMapIter.More())
1288 {
1289 myCurrentName = myMapIter.Key2();
1290 myCurrentTrs = myMapIter.Key1();
1291 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
eafb234b 1292 }
ad3217cd 1293 break;
1294 }
1295 case IterSource_List:
1296 {
1297 if (mySeqIter.More())
1298 {
1299 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1300 {
1301 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1302 return;
1303 }
1304 myCurrentName = mySeqIter.Value();
1305 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1306 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1307 }
1308 break;
1309 }
1310 case IterSource_Selected:
1311 {
c3282ec1 1312 if (mySelIter->MoreSelected())
ad3217cd 1313 {
c3282ec1 1314 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1315 myCurrent = mySelIter->SelectedInteractive();
ad3217cd 1316 }
1317 break;
7fd59977 1318 }
7fd59977 1319 }
1320 }
ad3217cd 1321
1322private:
1323
1324 enum IterSource
1325 {
1326 IterSource_All,
1327 IterSource_List,
1328 IterSource_Selected
1329 };
1330
1331private:
1332
1333 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1334 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1335 NCollection_Sequence<TCollection_AsciiString> mySeq;
1336 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1337
1338 TCollection_AsciiString myCurrentName;//!< current item name
1339 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1340 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1341
1342 IterSource mySource; //!< iterated collection
1343
1344};
7fd59977 1345
1346//==============================================================================
ad3217cd 1347//function : VInteriorStyle
1348//purpose : sets interior style of the a selected or named or displayed shape
7fd59977 1349//==============================================================================
ad3217cd 1350static int VSetInteriorStyle (Draw_Interpretor& theDI,
1351 Standard_Integer theArgNb,
1352 const char** theArgVec)
7fd59977 1353{
ad3217cd 1354 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1355 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1356 if (aCtx.IsNull())
1357 {
1358 std::cerr << "Error: no active view!\n";
1359 return 1;
1360 }
7fd59977 1361
4e18052b 1362 Standard_Integer anArgIter = 1;
ad3217cd 1363 for (; anArgIter < theArgNb; ++anArgIter)
1364 {
4e18052b 1365 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
ad3217cd 1366 {
1367 break;
1368 }
7fd59977 1369 }
ad3217cd 1370 TCollection_AsciiString aName;
1371 if (theArgNb - anArgIter == 2)
1372 {
1373 aName = theArgVec[anArgIter++];
1374 }
1375 else if (theArgNb - anArgIter != 1)
1376 {
1377 std::cout << "Error: wrong number of arguments! See usage:\n";
1378 theDI.PrintHelp (theArgVec[0]);
1379 return 1;
1380 }
1381 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1382 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1383 aStyleArg.LowerCase();
1384 if (aStyleArg == "empty")
1385 {
1386 anInterStyle = 0;
1387 }
1388 else if (aStyleArg == "hollow")
1389 {
1390 anInterStyle = 1;
1391 }
1392 else if (aStyleArg == "hatch")
1393 {
1394 anInterStyle = 2;
1395 }
1396 else if (aStyleArg == "solid")
1397 {
1398 anInterStyle = 3;
1399 }
1400 else if (aStyleArg == "hiddenline")
1401 {
1402 anInterStyle = 4;
1403 }
1404 else
1405 {
1406 anInterStyle = aStyleArg.IntegerValue();
1407 }
1408 if (anInterStyle < Aspect_IS_EMPTY
1409 || anInterStyle > Aspect_IS_HIDDENLINE)
1410 {
1411 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1412 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1413 return 1;
7fd59977 1414 }
1415
ad3217cd 1416 if (!aName.IsEmpty()
1417 && !GetMapOfAIS().IsBound2 (aName))
1418 {
1419 std::cout << "Error: object " << aName << " is not displayed!\n";
1420 return 1;
1421 }
1422
1423 if (aCtx->HasOpenedContext())
1424 {
1425 aCtx->CloseLocalContext();
1426 }
1427 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1428 {
1429 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1430 if (!anIO.IsNull())
1431 {
1432 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1433 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1434 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1435 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1436 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
7fd59977 1437 }
ad3217cd 1438 }
ad3217cd 1439 return 0;
1440}
7fd59977 1441
ad3217cd 1442//! Auxiliary structure for VAspects
1443struct ViewerTest_AspectsChangeSet
1444{
5bffb882 1445 Standard_Integer ToSetVisibility;
1446 Standard_Integer Visibility;
1447
ad3217cd 1448 Standard_Integer ToSetColor;
1449 Quantity_Color Color;
1450
1451 Standard_Integer ToSetLineWidth;
1452 Standard_Real LineWidth;
1453
ac116c22 1454 Standard_Integer ToSetTypeOfLine;
1455 Aspect_TypeOfLine TypeOfLine;
1456
ad3217cd 1457 Standard_Integer ToSetTransparency;
1458 Standard_Real Transparency;
1459
1460 Standard_Integer ToSetMaterial;
1461 Graphic3d_NameOfMaterial Material;
1462 TCollection_AsciiString MatName;
1463
1464 NCollection_Sequence<TopoDS_Shape> SubShapes;
1465
6262338c 1466 Standard_Integer ToSetShowFreeBoundary;
1467 Standard_Integer ToSetFreeBoundaryWidth;
1468 Standard_Real FreeBoundaryWidth;
1469 Standard_Integer ToSetFreeBoundaryColor;
1470 Quantity_Color FreeBoundaryColor;
1471
5ad8c033 1472 Standard_Integer ToEnableIsoOnTriangulation;
1473
1474 Standard_Integer ToSetMaxParamValue;
1475 Standard_Real MaxParamValue;
1476
8a1170ad 1477 Standard_Integer ToSetSensitivity;
1478 Standard_Integer SelectionMode;
1479 Standard_Integer Sensitivity;
1480
ad3217cd 1481 //! Empty constructor
1482 ViewerTest_AspectsChangeSet()
5bffb882 1483 : ToSetVisibility (0),
1484 Visibility (1),
1485 ToSetColor (0),
ad3217cd 1486 Color (DEFAULT_COLOR),
1487 ToSetLineWidth (0),
1488 LineWidth (1.0),
ac116c22 1489 ToSetTypeOfLine (0),
1490 TypeOfLine (Aspect_TOL_SOLID),
ad3217cd 1491 ToSetTransparency (0),
1492 Transparency (0.0),
1493 ToSetMaterial (0),
6262338c 1494 Material (Graphic3d_NOM_DEFAULT),
5ad8c033 1495 ToSetShowFreeBoundary (0),
1496 ToSetFreeBoundaryWidth (0),
1497 FreeBoundaryWidth (1.0),
1498 ToSetFreeBoundaryColor (0),
1499 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1500 ToEnableIsoOnTriangulation (-1),
1501 ToSetMaxParamValue (0),
8a1170ad 1502 MaxParamValue (500000),
1503 ToSetSensitivity (0),
1504 SelectionMode (-1),
1505 Sensitivity (-1) {}
ad3217cd 1506
1507 //! @return true if no changes have been requested
1508 Standard_Boolean IsEmpty() const
1509 {
6262338c 1510 return ToSetVisibility == 0
1511 && ToSetLineWidth == 0
1512 && ToSetTransparency == 0
1513 && ToSetColor == 0
1514 && ToSetMaterial == 0
1515 && ToSetShowFreeBoundary == 0
1516 && ToSetFreeBoundaryColor == 0
5ad8c033 1517 && ToSetFreeBoundaryWidth == 0
8a1170ad 1518 && ToSetMaxParamValue == 0
1519 && ToSetSensitivity == 0;
ad3217cd 1520 }
1521
1522 //! @return true if properties are valid
1523 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1524 {
1525 Standard_Boolean isOk = Standard_True;
5bffb882 1526 if (Visibility != 0 && Visibility != 1)
1527 {
1528 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1529 isOk = Standard_False;
1530 }
ad3217cd 1531 if (LineWidth <= 0.0
1532 || LineWidth > 10.0)
1533 {
1534 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1535 isOk = Standard_False;
7fd59977 1536 }
ad3217cd 1537 if (Transparency < 0.0
1538 || Transparency > 1.0)
1539 {
1540 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1541 isOk = Standard_False;
1542 }
1543 if (theIsSubPart
1544 && ToSetTransparency)
1545 {
1546 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1547 isOk = Standard_False;
7fd59977 1548 }
ad3217cd 1549 if (ToSetMaterial == 1
1550 && Material == Graphic3d_NOM_DEFAULT)
1551 {
1552 std::cout << "Error: unknown material " << MatName << ".\n";
1553 isOk = Standard_False;
1554 }
6262338c 1555 if (FreeBoundaryWidth <= 0.0
1556 || FreeBoundaryWidth > 10.0)
1557 {
1558 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1559 isOk = Standard_False;
1560 }
5ad8c033 1561 if (MaxParamValue < 0.0)
1562 {
1563 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1564 isOk = Standard_False;
1565 }
8a1170ad 1566 if (Sensitivity <= 0 && ToSetSensitivity)
1567 {
1568 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1569 isOk = Standard_False;
1570 }
ad3217cd 1571 return isOk;
7fd59977 1572 }
7fd59977 1573
ad3217cd 1574};
7fd59977 1575
1576//==============================================================================
ad3217cd 1577//function : VAspects
1578//purpose :
7fd59977 1579//==============================================================================
ad3217cd 1580static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1581 Standard_Integer theArgNb,
1582 const char** theArgVec)
7fd59977 1583{
ad3217cd 1584 TCollection_AsciiString aCmdName (theArgVec[0]);
1585 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1586 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1587 if (aCtx.IsNull())
1588 {
1589 std::cerr << "Error: no active view!\n";
1590 return 1;
1591 }
7fd59977 1592
4e18052b 1593 Standard_Integer anArgIter = 1;
6262338c 1594 Standard_Boolean isDefaults = Standard_False;
ad3217cd 1595 NCollection_Sequence<TCollection_AsciiString> aNames;
1596 for (; anArgIter < theArgNb; ++anArgIter)
1597 {
1598 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 1599 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 1600 {
1601 continue;
1602 }
1603 else if (!anArg.IsEmpty()
1604 && anArg.Value (1) != '-')
1605 {
1606 aNames.Append (anArg);
1607 }
1608 else
1609 {
6262338c 1610 if (anArg == "-defaults")
1611 {
1612 isDefaults = Standard_True;
1613 ++anArgIter;
1614 }
ad3217cd 1615 break;
1616 }
1617 }
1618
6262338c 1619 if (!aNames.IsEmpty() && isDefaults)
1620 {
1621 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1622 return 1;
1623 }
1624
ad3217cd 1625 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1626 aChanges.Append (ViewerTest_AspectsChangeSet());
1627 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 1628
ad3217cd 1629 // parse syntax of legacy commands
1630 if (aCmdName == "vsetwidth")
1631 {
1632 if (aNames.IsEmpty()
1633 || !aNames.Last().IsRealValue())
1634 {
1635 std::cout << "Error: not enough arguments!\n";
1636 return 1;
1637 }
1638 aChangeSet->ToSetLineWidth = 1;
1639 aChangeSet->LineWidth = aNames.Last().RealValue();
1640 aNames.Remove (aNames.Length());
7fd59977 1641 }
ad3217cd 1642 else if (aCmdName == "vunsetwidth")
1643 {
1644 aChangeSet->ToSetLineWidth = -1;
1645 }
1646 else if (aCmdName == "vsetcolor")
1647 {
1648 if (aNames.IsEmpty())
1649 {
1650 std::cout << "Error: not enough arguments!\n";
1651 return 1;
1652 }
1653 aChangeSet->ToSetColor = 1;
8316c618 1654
1655 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1656 Standard_Boolean isOk = Standard_False;
1657 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1658 {
1659 aChangeSet->Color = aColor;
1660 aNames.Remove (aNames.Length());
1661 isOk = Standard_True;
1662 }
1663 else if (aNames.Length() >= 3)
1664 {
1665 const TCollection_AsciiString anRgbStr[3] =
1666 {
1667 aNames.Value (aNames.Upper() - 2),
1668 aNames.Value (aNames.Upper() - 1),
1669 aNames.Value (aNames.Upper() - 0)
1670 };
1671 isOk = anRgbStr[0].IsRealValue()
1672 && anRgbStr[1].IsRealValue()
1673 && anRgbStr[2].IsRealValue();
1674 if (isOk)
1675 {
1676 Graphic3d_Vec4d anRgb;
1677 anRgb.x() = anRgbStr[0].RealValue();
1678 anRgb.y() = anRgbStr[1].RealValue();
1679 anRgb.z() = anRgbStr[2].RealValue();
1680 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1681 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1682 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1683 {
1684 std::cout << "Error: RGB color values should be within range 0..1!\n";
1685 return 1;
1686 }
1687 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1688 aNames.Remove (aNames.Length());
1689 aNames.Remove (aNames.Length());
1690 aNames.Remove (aNames.Length());
1691 }
1692 }
1693 if (!isOk)
1694 {
1695 std::cout << "Error: not enough arguments!\n";
1696 return 1;
1697 }
ad3217cd 1698 }
1699 else if (aCmdName == "vunsetcolor")
1700 {
1701 aChangeSet->ToSetColor = -1;
1702 }
1703 else if (aCmdName == "vsettransparency")
1704 {
1705 if (aNames.IsEmpty()
1706 || !aNames.Last().IsRealValue())
1707 {
1708 std::cout << "Error: not enough arguments!\n";
1709 return 1;
1710 }
1711 aChangeSet->ToSetTransparency = 1;
1712 aChangeSet->Transparency = aNames.Last().RealValue();
1713 aNames.Remove (aNames.Length());
1714 }
1715 else if (aCmdName == "vunsettransparency")
1716 {
1717 aChangeSet->ToSetTransparency = -1;
1718 }
1719 else if (aCmdName == "vsetmaterial")
1720 {
1721 if (aNames.IsEmpty())
1722 {
1723 std::cout << "Error: not enough arguments!\n";
1724 return 1;
1725 }
1726 aChangeSet->ToSetMaterial = 1;
1727 aChangeSet->MatName = aNames.Last();
1728 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1729 aNames.Remove (aNames.Length());
1730 }
1731 else if (aCmdName == "vunsetmaterial")
1732 {
1733 aChangeSet->ToSetMaterial = -1;
1734 }
1735 else if (anArgIter >= theArgNb)
1736 {
1737 std::cout << "Error: not enough arguments!\n";
1738 return 1;
7fd59977 1739 }
1740
ad3217cd 1741 if (!aChangeSet->IsEmpty())
1742 {
1743 anArgIter = theArgNb;
1744 }
1745 for (; anArgIter < theArgNb; ++anArgIter)
1746 {
1747 TCollection_AsciiString anArg = theArgVec[anArgIter];
1748 anArg.LowerCase();
1749 if (anArg == "-setwidth"
1750 || anArg == "-setlinewidth")
1751 {
1752 if (++anArgIter >= theArgNb)
1753 {
1754 std::cout << "Error: wrong syntax at " << anArg << "\n";
1755 return 1;
1756 }
1757 aChangeSet->ToSetLineWidth = 1;
1758 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1759 }
ad3217cd 1760 else if (anArg == "-unsetwidth"
1761 || anArg == "-unsetlinewidth")
1762 {
1763 aChangeSet->ToSetLineWidth = -1;
1764 aChangeSet->LineWidth = 1.0;
1765 }
1766 else if (anArg == "-settransp"
0ae61cf3 1767 || anArg == "-settransparency")
ad3217cd 1768 {
1769 if (++anArgIter >= theArgNb)
1770 {
1771 std::cout << "Error: wrong syntax at " << anArg << "\n";
1772 return 1;
1773 }
1774 aChangeSet->ToSetTransparency = 1;
1775 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1776 if (aChangeSet->Transparency >= 0.0
1777 && aChangeSet->Transparency <= Precision::Confusion())
1778 {
1779 aChangeSet->ToSetTransparency = -1;
1780 aChangeSet->Transparency = 0.0;
eafb234b 1781 }
7fd59977 1782 }
5bffb882 1783 else if (anArg == "-setvis"
1784 || anArg == "-setvisibility")
1785 {
1786 if (++anArgIter >= theArgNb)
1787 {
1788 std::cout << "Error: wrong syntax at " << anArg << "\n";
1789 return 1;
1790 }
1791
1792 aChangeSet->ToSetVisibility = 1;
1793 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1794 }
ad3217cd 1795 else if (anArg == "-setalpha")
1796 {
1797 if (++anArgIter >= theArgNb)
7fd59977 1798 {
ad3217cd 1799 std::cout << "Error: wrong syntax at " << anArg << "\n";
1800 return 1;
1801 }
1802 aChangeSet->ToSetTransparency = 1;
1803 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1804 if (aChangeSet->Transparency < 0.0
1805 || aChangeSet->Transparency > 1.0)
1806 {
1807 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1808 return 1;
1809 }
1810 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1811 if (aChangeSet->Transparency >= 0.0
1812 && aChangeSet->Transparency <= Precision::Confusion())
1813 {
1814 aChangeSet->ToSetTransparency = -1;
1815 aChangeSet->Transparency = 0.0;
7fd59977 1816 }
7fd59977 1817 }
ad3217cd 1818 else if (anArg == "-unsettransp"
0ae61cf3 1819 || anArg == "-unsettransparency"
ad3217cd 1820 || anArg == "-unsetalpha"
1821 || anArg == "-opaque")
1822 {
1823 aChangeSet->ToSetTransparency = -1;
1824 aChangeSet->Transparency = 0.0;
1825 }
1826 else if (anArg == "-setcolor")
1827 {
8316c618 1828 Standard_Integer aNbComps = 0;
1829 Standard_Integer aCompIter = anArgIter + 1;
1830 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
ad3217cd 1831 {
8316c618 1832 if (theArgVec[aCompIter][0] == '-')
1833 {
1834 break;
1835 }
1836 }
1837 switch (aNbComps)
1838 {
1839 case 1:
1840 {
1841 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1842 Standard_CString aName = theArgVec[anArgIter + 1];
1843 if (!Quantity_Color::ColorFromName (aName, aColor))
1844 {
1845 std::cout << "Error: unknown color name '" << aName << "'\n";
1846 return 1;
1847 }
1848 aChangeSet->Color = aColor;
1849 break;
1850 }
1851 case 3:
1852 {
1853 Graphic3d_Vec3d anRgb;
1854 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1855 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1856 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1857 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1858 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1859 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1860 {
1861 std::cout << "Error: RGB color values should be within range 0..1!\n";
1862 return 1;
1863 }
1864 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1865 break;
1866 }
1867 default:
1868 {
1869 std::cout << "Error: wrong syntax at " << anArg << "\n";
1870 return 1;
1871 }
7fd59977 1872 }
ad3217cd 1873 aChangeSet->ToSetColor = 1;
8316c618 1874 anArgIter += aNbComps;
7fd59977 1875 }
ac116c22 1876 else if (anArg == "-setlinetype")
1877 {
1878 if (++anArgIter >= theArgNb)
1879 {
1880 std::cout << "Error: wrong syntax at " << anArg << "\n";
1881 return 1;
1882 }
1883
1884 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1885 aValue.LowerCase();
1886
1887 if (aValue.IsEqual ("solid"))
1888 {
1889 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1890 }
1891 else if (aValue.IsEqual ("dot"))
1892 {
1893 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1894 }
1895 else if (aValue.IsEqual ("dash"))
1896 {
1897 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1898 }
1899 else if (aValue.IsEqual ("dotdash"))
1900 {
1901 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1902 }
1903 else
1904 {
1905 std::cout << "Error: wrong syntax at " << anArg << "\n";
1906 return 1;
1907 }
1908
1909 aChangeSet->ToSetTypeOfLine = 1;
1910 }
1911 else if (anArg == "-unsetlinetype")
1912 {
1913 aChangeSet->ToSetTypeOfLine = -1;
1914 }
ad3217cd 1915 else if (anArg == "-unsetcolor")
1916 {
1917 aChangeSet->ToSetColor = -1;
1918 aChangeSet->Color = DEFAULT_COLOR;
1919 }
1920 else if (anArg == "-setmat"
1921 || anArg == "-setmaterial")
1922 {
1923 if (++anArgIter >= theArgNb)
1924 {
1925 std::cout << "Error: wrong syntax at " << anArg << "\n";
1926 return 1;
1927 }
1928 aChangeSet->ToSetMaterial = 1;
1929 aChangeSet->MatName = theArgVec[anArgIter];
1930 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1931 }
1932 else if (anArg == "-unsetmat"
1933 || anArg == "-unsetmaterial")
1934 {
1935 aChangeSet->ToSetMaterial = -1;
1936 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1937 }
1938 else if (anArg == "-subshape"
1939 || anArg == "-subshapes")
1940 {
6262338c 1941 if (isDefaults)
1942 {
1943 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1944 return 1;
1945 }
1946
ad3217cd 1947 if (aNames.IsEmpty())
1948 {
1949 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1950 return 1;
1951 }
7fd59977 1952
ad3217cd 1953 aChanges.Append (ViewerTest_AspectsChangeSet());
1954 aChangeSet = &aChanges.ChangeLast();
7fd59977 1955
ad3217cd 1956 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1957 {
1958 Standard_CString aSubShapeName = theArgVec[anArgIter];
1959 if (*aSubShapeName == '-')
1960 {
1961 --anArgIter;
1962 break;
1963 }
7fd59977 1964
ad3217cd 1965 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1966 if (aSubShape.IsNull())
1967 {
1968 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1969 return 1;
1970 }
1971 aChangeSet->SubShapes.Append (aSubShape);
1972 }
7fd59977 1973
ad3217cd 1974 if (aChangeSet->SubShapes.IsEmpty())
1975 {
1976 std::cerr << "Error: empty list is specified after -subshapes!\n";
1977 return 1;
1978 }
1979 }
6262338c 1980 else if (anArg == "-freeboundary"
1981 || anArg == "-fb")
1982 {
1983 if (++anArgIter >= theArgNb)
1984 {
1985 std::cout << "Error: wrong syntax at " << anArg << "\n";
1986 return 1;
1987 }
1988 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1989 aValue.LowerCase();
1990 if (aValue == "on"
1991 || aValue == "1")
1992 {
1993 aChangeSet->ToSetShowFreeBoundary = 1;
1994 }
1995 else if (aValue == "off"
1996 || aValue == "0")
1997 {
1998 aChangeSet->ToSetShowFreeBoundary = -1;
1999 }
2000 else
2001 {
2002 std::cout << "Error: wrong syntax at " << anArg << "\n";
2003 return 1;
2004 }
2005 }
2006 else if (anArg == "-setfreeboundarywidth"
2007 || anArg == "-setfbwidth")
2008 {
2009 if (++anArgIter >= theArgNb)
2010 {
2011 std::cout << "Error: wrong syntax at " << anArg << "\n";
2012 return 1;
2013 }
2014 aChangeSet->ToSetFreeBoundaryWidth = 1;
2015 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2016 }
2017 else if (anArg == "-unsetfreeboundarywidth"
2018 || anArg == "-unsetfbwidth")
2019 {
2020 aChangeSet->ToSetFreeBoundaryWidth = -1;
2021 aChangeSet->FreeBoundaryWidth = 1.0;
2022 }
2023 else if (anArg == "-setfreeboundarycolor"
2024 || anArg == "-setfbcolor")
2025 {
2026 Standard_Integer aNbComps = 0;
2027 Standard_Integer aCompIter = anArgIter + 1;
2028 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2029 {
2030 if (theArgVec[aCompIter][0] == '-')
2031 {
2032 break;
2033 }
2034 }
2035 switch (aNbComps)
2036 {
2037 case 1:
2038 {
2039 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2040 Standard_CString aName = theArgVec[anArgIter + 1];
2041 if (!Quantity_Color::ColorFromName (aName, aColor))
2042 {
2043 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2044 return 1;
2045 }
2046 aChangeSet->FreeBoundaryColor = aColor;
2047 break;
2048 }
2049 case 3:
2050 {
2051 Graphic3d_Vec3d anRgb;
2052 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2053 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2054 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2055 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2056 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2057 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2058 {
2059 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2060 return 1;
2061 }
2062 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2063 break;
2064 }
2065 default:
2066 {
2067 std::cout << "Error: wrong syntax at " << anArg << "\n";
2068 return 1;
2069 }
2070 }
2071 aChangeSet->ToSetFreeBoundaryColor = 1;
2072 anArgIter += aNbComps;
2073 }
2074 else if (anArg == "-unsetfreeboundarycolor"
2075 || anArg == "-unsetfbcolor")
2076 {
2077 aChangeSet->ToSetFreeBoundaryColor = -1;
2078 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2079 }
ad3217cd 2080 else if (anArg == "-unset")
2081 {
5bffb882 2082 aChangeSet->ToSetVisibility = 1;
2083 aChangeSet->Visibility = 1;
ad3217cd 2084 aChangeSet->ToSetLineWidth = -1;
2085 aChangeSet->LineWidth = 1.0;
ac116c22 2086 aChangeSet->ToSetTypeOfLine = -1;
2087 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
ad3217cd 2088 aChangeSet->ToSetTransparency = -1;
2089 aChangeSet->Transparency = 0.0;
2090 aChangeSet->ToSetColor = -1;
2091 aChangeSet->Color = DEFAULT_COLOR;
2092 aChangeSet->ToSetMaterial = -1;
2093 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
6262338c 2094 aChangeSet->ToSetShowFreeBoundary = -1;
2095 aChangeSet->ToSetFreeBoundaryColor = -1;
2096 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2097 aChangeSet->ToSetFreeBoundaryWidth = -1;
2098 aChangeSet->FreeBoundaryWidth = 1.0;
7fd59977 2099 }
5ad8c033 2100 else if (anArg == "-isoontriangulation"
2101 || anArg == "-isoontriang")
2102 {
2103 if (++anArgIter >= theArgNb)
2104 {
2105 std::cout << "Error: wrong syntax at " << anArg << "\n";
2106 return 1;
2107 }
2108 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2109 aValue.LowerCase();
2110 if (aValue == "on"
2111 || aValue == "1")
2112 {
2113 aChangeSet->ToEnableIsoOnTriangulation = 1;
2114 }
2115 else if (aValue == "off"
2116 || aValue == "0")
2117 {
2118 aChangeSet->ToEnableIsoOnTriangulation = 0;
2119 }
2120 else
2121 {
2122 std::cout << "Error: wrong syntax at " << anArg << "\n";
2123 return 1;
2124 }
2125 }
2126 else if (anArg == "-setmaxparamvalue")
2127 {
2128 if (++anArgIter >= theArgNb)
2129 {
2130 std::cout << "Error: wrong syntax at " << anArg << "\n";
2131 return 1;
2132 }
2133 aChangeSet->ToSetMaxParamValue = 1;
2134 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2135 }
8a1170ad 2136 else if (anArg == "-setsensitivity")
2137 {
2138 if (isDefaults)
2139 {
2140 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2141 return 1;
2142 }
2143
2144 if (aNames.IsEmpty())
2145 {
2146 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2147 return 1;
2148 }
2149
2150 if (anArgIter + 2 >= theArgNb)
2151 {
2152 std::cout << "Error: wrong syntax at " << anArg << "\n";
2153 return 1;
2154 }
2155 aChangeSet->ToSetSensitivity = 1;
2156 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2157 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2158 }
7fd59977 2159 else
ad3217cd 2160 {
2161 std::cout << "Error: wrong syntax at " << anArg << "\n";
2162 return 1;
2163 }
7fd59977 2164 }
99c56d44 2165
ad3217cd 2166 Standard_Boolean isFirst = Standard_True;
2167 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2168 aChangesIter.More(); aChangesIter.Next())
2169 {
2170 if (!aChangesIter.Value().Validate (!isFirst))
2171 {
2172 return 1;
2173 }
2174 isFirst = Standard_False;
99c56d44 2175 }
99c56d44 2176
ad3217cd 2177 if (aCtx->HasOpenedContext())
2178 {
2179 aCtx->CloseLocalContext();
99c56d44 2180 }
6262338c 2181
2182 // special case for -defaults parameter.
2183 // all changed values will be set to DefaultDrawer.
2184 if (isDefaults)
2185 {
2186 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2187
2188 if (aChangeSet->ToSetLineWidth != 0)
2189 {
2190 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2191 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2192 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2193 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2194 }
2195 if (aChangeSet->ToSetColor != 0)
2196 {
2197 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2198 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2199 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2200 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2201 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2202 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2203 }
ac116c22 2204 if (aChangeSet->ToSetTypeOfLine != 0)
2205 {
2206 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2207 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2208 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2209 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2210 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2211 }
6262338c 2212 if (aChangeSet->ToSetTransparency != 0)
2213 {
2214 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2215 }
2216 if (aChangeSet->ToSetMaterial != 0)
2217 {
2218 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2219 }
2220 if (aChangeSet->ToSetShowFreeBoundary == 1)
2221 {
2222 aDrawer->SetFreeBoundaryDraw (Standard_True);
2223 }
2224 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2225 {
2226 aDrawer->SetFreeBoundaryDraw (Standard_False);
2227 }
2228 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2229 {
2230 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2231 }
2232 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2233 {
2234 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2235 }
5ad8c033 2236 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2237 {
2238 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2239 }
2240 if (aChangeSet->ToSetMaxParamValue != 0)
2241 {
2242 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2243 }
6262338c 2244
2245 // redisplay all objects in context
2246 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2247 {
2248 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2249 if (!aPrs.IsNull())
2250 {
2251 aCtx->Redisplay (aPrs, Standard_False);
2252 }
2253 }
2254 return 0;
2255 }
2256
ad3217cd 2257 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2258 {
6262338c 2259 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2260 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2261 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 2262 Handle(AIS_ColoredShape) aColoredPrs;
2263 Standard_Boolean toDisplay = Standard_False;
6262338c 2264 Standard_Boolean toRedisplay = Standard_False;
5bffb882 2265 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 2266 {
2267 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2268 if (aShapePrs.IsNull())
2269 {
2270 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2271 return 1;
2272 }
2273 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2274 if (aColoredPrs.IsNull())
2275 {
2276 aColoredPrs = new AIS_ColoredShape (aShapePrs);
3e05329c 2277 if (aShapePrs->HasDisplayMode())
2278 {
2279 aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode());
2280 }
2281 aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation());
ad3217cd 2282 aCtx->Remove (aShapePrs, Standard_False);
2283 GetMapOfAIS().UnBind2 (aName);
2284 GetMapOfAIS().Bind (aColoredPrs, aName);
2285 toDisplay = Standard_True;
2286 aShapePrs = aColoredPrs;
2287 aPrs = aColoredPrs;
2288 }
2289 }
99c56d44 2290
ad3217cd 2291 if (!aPrs.IsNull())
2292 {
2293 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2294 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2295 if (aChangeSet->ToSetVisibility == 1)
2296 {
2297 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2298 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2299 }
2300 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2301 {
2302 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2303 }
2304 else if (aChangeSet->ToSetMaterial == -1)
2305 {
2306 aCtx->UnsetMaterial (aPrs, Standard_False);
2307 }
2308 if (aChangeSet->ToSetColor == 1)
2309 {
2310 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2311 }
2312 else if (aChangeSet->ToSetColor == -1)
2313 {
2314 aCtx->UnsetColor (aPrs, Standard_False);
2315 }
2316 if (aChangeSet->ToSetTransparency == 1)
2317 {
2318 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2319 }
2320 else if (aChangeSet->ToSetTransparency == -1)
2321 {
2322 aCtx->UnsetTransparency (aPrs, Standard_False);
2323 }
2324 if (aChangeSet->ToSetLineWidth == 1)
2325 {
2326 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2327 }
2328 else if (aChangeSet->ToSetLineWidth == -1)
2329 {
2330 aCtx->UnsetWidth (aPrs, Standard_False);
2331 }
5ad8c033 2332 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2333 {
2334 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2335 toRedisplay = Standard_True;
2336 }
8a1170ad 2337 else if (aChangeSet->ToSetSensitivity != 0)
2338 {
2339 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2340 }
6262338c 2341 if (!aDrawer.IsNull())
2342 {
2343 if (aChangeSet->ToSetShowFreeBoundary == 1)
2344 {
2345 aDrawer->SetFreeBoundaryDraw (Standard_True);
2346 toRedisplay = Standard_True;
2347 }
2348 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2349 {
2350 aDrawer->SetFreeBoundaryDraw (Standard_False);
2351 toRedisplay = Standard_True;
2352 }
2353 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2354 {
2355 Handle(Prs3d_LineAspect) aBoundaryAspect =
2356 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2357 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2358 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2359 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2360 toRedisplay = Standard_True;
2361 }
2362 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2363 {
2364 Handle(Prs3d_LineAspect) aBoundaryAspect =
2365 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2366 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2367 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2368 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2369 toRedisplay = Standard_True;
2370 }
ac116c22 2371 if (aChangeSet->ToSetTypeOfLine != 0)
2372 {
2373 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2374 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2375 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2376 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2377 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2378 toRedisplay = Standard_True;
2379 }
5ad8c033 2380 if (aChangeSet->ToSetMaxParamValue != 0)
2381 {
2382 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2383 }
6262338c 2384 }
99c56d44 2385
ad3217cd 2386 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2387 {
2388 aChangeSet = &aChangesIter.ChangeValue();
2389 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2390 aSubShapeIter.More(); aSubShapeIter.Next())
2391 {
2392 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2393 if (aChangeSet->ToSetVisibility == 1)
2394 {
2395 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2396 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2397 }
ad3217cd 2398 if (aChangeSet->ToSetColor == 1)
2399 {
2400 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2401 }
2402 if (aChangeSet->ToSetLineWidth == 1)
2403 {
2404 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2405 }
2406 if (aChangeSet->ToSetColor == -1
2407 || aChangeSet->ToSetLineWidth == -1)
2408 {
2409 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2410 }
5ad8c033 2411 if (aChangeSet->ToSetMaxParamValue != 0)
2412 {
2413 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2414 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2415 }
8a1170ad 2416 if (aChangeSet->ToSetSensitivity != 0)
2417 {
2418 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2419 }
ad3217cd 2420 }
2421 }
2422 if (toDisplay)
2423 {
2424 aCtx->Display (aPrs, Standard_False);
2425 }
6262338c 2426 if (toRedisplay)
2427 {
2428 aCtx->Redisplay (aPrs, Standard_False);
2429 }
ad3217cd 2430 else if (!aColoredPrs.IsNull())
2431 {
36132a2e 2432 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2433 }
99c56d44 2434 }
ad3217cd 2435 }
99c56d44 2436 return 0;
2437}
2438
7fd59977 2439//==============================================================================
2440//function : VDonly2
2441//author : ege
2442//purpose : Display only a selected or named object
519d35d8 2443// if there is no selected or named object s, nothing is done
7fd59977 2444//==============================================================================
519d35d8 2445static int VDonly2 (Draw_Interpretor& ,
2446 Standard_Integer theArgNb,
2447 const char** theArgVec)
7fd59977 2448{
519d35d8 2449 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2450 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2451 if (aCtx.IsNull())
2452 {
2453 std::cerr << "Error: no active view!\n";
7fd59977 2454 return 1;
519d35d8 2455 }
7fd59977 2456
519d35d8 2457 if (aCtx->HasOpenedContext())
2458 {
2459 aCtx->CloseLocalContext();
2460 }
7fd59977 2461
519d35d8 2462 Standard_Integer anArgIter = 1;
2463 for (; anArgIter < theArgNb; ++anArgIter)
2464 {
4e18052b 2465 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2466 {
2467 break;
2468 }
2469 }
7fd59977 2470
519d35d8 2471 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2472 if (anArgIter >= theArgNb)
2473 {
2474 // display only selected objects
c3282ec1 2475 if (aCtx->NbSelected() < 1)
519d35d8 2476 {
2477 return 0;
7fd59977 2478 }
2479
c3282ec1 2480 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
519d35d8 2481 {
c3282ec1 2482 aDispSet.Add (aCtx->SelectedInteractive());
519d35d8 2483 }
2484 }
2485 else
2486 {
2487 // display only specified objects
2488 for (; anArgIter < theArgNb; ++anArgIter)
2489 {
2490 TCollection_AsciiString aName = theArgVec[anArgIter];
2491 if (GetMapOfAIS().IsBound2 (aName))
2492 {
d09dda09 2493 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2494 if (!aShape.IsNull())
519d35d8 2495 {
519d35d8 2496 aCtx->Display (aShape, Standard_False);
d09dda09 2497 aDispSet.Add (aShape);
519d35d8 2498 }
7fd59977 2499 }
2500 }
7fd59977 2501 }
519d35d8 2502
2503 // weed out other objects
2504 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2505 {
2506 if (aDispSet.Contains (anIter.Key1()))
2507 {
2508 continue;
2509 }
2510
d09dda09 2511 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2512 if (aShape.IsNull())
519d35d8 2513 {
519d35d8 2514 aCtx->Erase (aShape, Standard_False);
2515 }
519d35d8 2516 }
7fd59977 2517 return 0;
2518}
2519
eef7fc64 2520//==============================================================================
2521//function : VRemove
2522//purpose : Removes selected or named objects.
2523// If there is no selected or named objects,
2524// all objects in the viewer can be removed with argument -all.
2525// If -context is in arguments, the object is not deleted from the map of
2526// objects (deleted only from the current context).
2527//==============================================================================
2528int VRemove (Draw_Interpretor& theDI,
519d35d8 2529 Standard_Integer theArgNb,
2530 const char** theArgVec)
eef7fc64 2531{
4e18052b 2532 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2533 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2534 if (aCtx.IsNull())
eef7fc64 2535 {
b6d587e3 2536 std::cerr << "Error: no active view!\n";
eef7fc64 2537 return 1;
2538 }
2539
4e18052b 2540 Standard_Boolean isContextOnly = Standard_False;
2541 Standard_Boolean toRemoveAll = Standard_False;
2542 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2543 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2544
2545 Standard_Integer anArgIter = 1;
2546 for (; anArgIter < theArgNb; ++anArgIter)
2547 {
2548 TCollection_AsciiString anArg = theArgVec[anArgIter];
2549 anArg.LowerCase();
2550 if (anArg == "-context")
2551 {
2552 isContextOnly = Standard_True;
2553 }
2554 else if (anArg == "-all")
2555 {
2556 toRemoveAll = Standard_True;
2557 }
b7cd4ba7 2558 else if (anArg == "-noinfo")
2559 {
2560 toPrintInfo = Standard_False;
2561 }
b6d587e3 2562 else if (anArg == "-local")
2563 {
2564 toRemoveLocal = Standard_True;
2565 }
2566 else if (anUpdateTool.parseRedrawMode (anArg))
2567 {
2568 continue;
2569 }
2570 else
519d35d8 2571 {
2572 break;
2573 }
2574 }
2575 if (toRemoveAll
2576 && anArgIter < theArgNb)
2577 {
b6d587e3 2578 std::cerr << "Error: wrong syntax!\n";
2579 return 1;
2580 }
2581
2582 if (toRemoveLocal && !aCtx->HasOpenedContext())
2583 {
2584 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2585 return 1;
2586 }
b6d587e3 2587 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2588 {
2589 aCtx->CloseAllContexts (Standard_False);
2590 }
519d35d8 2591
eef7fc64 2592 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2593 if (toRemoveAll)
eef7fc64 2594 {
2595 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2596 anIter.More(); anIter.Next())
2597 {
2598 anIONameList.Append (anIter.Key2());
2599 }
2600 }
519d35d8 2601 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2602 {
519d35d8 2603 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2604 {
519d35d8 2605 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2606 if (!GetMapOfAIS().IsBound2 (aName))
2607 {
2608 theDI << aName.ToCString() << " was not bound to some object.\n";
2609 continue;
2610 }
2611
d09dda09 2612 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2613 if (anIO->GetContext() != aCtx)
eef7fc64 2614 {
d09dda09 2615 theDI << aName.ToCString() << " was not displayed in current context.\n";
2616 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 2617 continue;
2618 }
2619
d09dda09 2620 anIONameList.Append (aName);
2621 continue;
eef7fc64 2622 }
2623 }
c3282ec1 2624 else if (aCtx->NbSelected() > 0)
eef7fc64 2625 {
2626 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2627 anIter.More(); anIter.Next())
2628 {
2629 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
c3282ec1 2630 if (!aCtx->IsSelected (anIO))
eef7fc64 2631 {
eef7fc64 2632 continue;
2633 }
2634
d09dda09 2635 anIONameList.Append (anIter.Key2());
2636 continue;
eef7fc64 2637 }
2638 }
2639
2640 // Unbind all removed objects from the map of displayed IO.
2641 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2642 anIter.More(); anIter.Next())
2643 {
519d35d8 2644 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
d09dda09 2645 aCtx->Remove (anIO, Standard_False);
2646 if (toPrintInfo)
519d35d8 2647 {
d09dda09 2648 theDI << anIter.Value().ToCString() << " was removed\n";
519d35d8 2649 }
519d35d8 2650 if (!isContextOnly)
2651 {
2652 GetMapOfAIS().UnBind2 (anIter.Value());
2653 }
2654 }
b6d587e3 2655
2656 // Close local context if it is empty
2657 TColStd_MapOfTransient aLocalIO;
2658 if (aCtx->HasOpenedContext()
2659 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2660 {
2661 aCtx->CloseAllContexts (Standard_False);
2662 }
2663
eef7fc64 2664 return 0;
2665}
2666
7fd59977 2667//==============================================================================
b514beda 2668//function : VErase
2669//purpose : Erase some selected or named objects
7fd59977 2670// if there is no selected or named objects, the whole viewer is erased
7fd59977 2671//==============================================================================
b514beda 2672int VErase (Draw_Interpretor& theDI,
2673 Standard_Integer theArgNb,
2674 const char** theArgVec)
7fd59977 2675{
a1954302 2676 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2677 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2678 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2679 if (aCtx.IsNull())
b514beda 2680 {
b6d587e3 2681 std::cerr << "Error: no active view!\n";
7fd59977 2682 return 1;
b514beda 2683 }
519d35d8 2684
519d35d8 2685 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2686
2687 Standard_Integer anArgIter = 1;
a272ed94 2688 Standard_Boolean toEraseLocal = Standard_False;
2689 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2690 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2691 for (; anArgIter < theArgNb; ++anArgIter)
2692 {
b6d587e3 2693 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2694 anArgCase.LowerCase();
2695 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2696 {
b6d587e3 2697 continue;
2698 }
2699 else if (anArgCase == "-local")
2700 {
2701 toEraseLocal = Standard_True;
2702 }
a272ed94 2703 else if (anArgCase == "-view"
2704 || anArgCase == "-inview")
2705 {
2706 toEraseInView = Standard_True;
2707 }
b6d587e3 2708 else
2709 {
2710 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2711 }
2712 }
2713
b6d587e3 2714 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2715 {
b6d587e3 2716 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2717 return 1;
2718 }
7fd59977 2719
b6d587e3 2720 if (toEraseLocal && !aCtx->HasOpenedContext())
2721 {
2722 std::cerr << "Error: local selection context is not open.\n";
2723 return 1;
2724 }
2725 else if (!toEraseLocal && aCtx->HasOpenedContext())
2726 {
2727 aCtx->CloseAllContexts (Standard_False);
2728 }
2729
2730 if (!aNamesOfEraseIO.IsEmpty())
2731 {
2732 // Erase named objects
2733 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2734 {
b6d587e3 2735 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2736 if (!GetMapOfAIS().IsBound2 (aName))
2737 {
2738 continue;
2739 }
7fd59977 2740
b514beda 2741 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2742 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2743 theDI << aName.ToCString() << " ";
2744 if (!anIO.IsNull())
2745 {
a272ed94 2746 if (toEraseInView)
2747 {
2748 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2749 }
2750 else
2751 {
2752 aCtx->Erase (anIO, Standard_False);
2753 }
b514beda 2754 }
7fd59977 2755 }
7fd59977 2756 }
c3282ec1 2757 else if (!toEraseAll && aCtx->NbSelected() > 0)
b514beda 2758 {
b6d587e3 2759 // Erase selected objects
671b6fe0 2760 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
b514beda 2761 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2762 anIter.More(); anIter.Next())
2763 {
2764 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2765 if (!anIO.IsNull()
c3282ec1 2766 && aCtx->IsSelected (anIO))
b514beda 2767 {
2768 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2769 if (toEraseInView)
2770 {
2771 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2772 }
671b6fe0 2773 else if (aHasOpenedContext)
a272ed94 2774 {
2775 aCtx->Erase (anIO, Standard_False);
2776 }
7fd59977 2777 }
2778 }
671b6fe0 2779
2780 if (!toEraseInView)
2781 {
2782 aCtx->EraseSelected (Standard_False);
2783 }
b514beda 2784 }
519d35d8 2785 else
b514beda 2786 {
b6d587e3 2787 // Erase all objects
519d35d8 2788 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2789 anIter.More(); anIter.Next())
b514beda 2790 {
519d35d8 2791 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2792 if (!anIO.IsNull())
2793 {
a272ed94 2794 if (toEraseInView)
2795 {
2796 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2797 }
2798 else
2799 {
2800 aCtx->Erase (anIO, Standard_False);
2801 }
519d35d8 2802 }
7fd59977 2803 }
7fd59977 2804 }
b6d587e3 2805
7fd59977 2806 return 0;
2807}
2808
7fd59977 2809//==============================================================================
2810//function : VDisplayAll
2811//author : ege
2812//purpose : Display all the objects of the Map
7fd59977 2813//==============================================================================
519d35d8 2814static int VDisplayAll (Draw_Interpretor& ,
2815 Standard_Integer theArgNb,
2816 const char** theArgVec)
7fd59977 2817
2818{
4e18052b 2819 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2820 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2821 if (aCtx.IsNull())
519d35d8 2822 {
b6d587e3 2823 std::cerr << "Error: no active view!\n";
519d35d8 2824 return 1;
2825 }
2826
519d35d8 2827 Standard_Integer anArgIter = 1;
b6d587e3 2828 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2829 for (; anArgIter < theArgNb; ++anArgIter)
2830 {
b6d587e3 2831 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2832 anArgCase.LowerCase();
2833 if (anArgCase == "-local")
2834 {
2835 toDisplayLocal = Standard_True;
2836 }
2837 else if (anUpdateTool.parseRedrawMode (anArgCase))
2838 {
2839 continue;
2840 }
2841 else
519d35d8 2842 {
2843 break;
7fd59977 2844 }
519d35d8 2845 }
2846 if (anArgIter < theArgNb)
2847 {
2848 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2849 return 1;
2850 }
2851
b6d587e3 2852 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2853 {
b6d587e3 2854 std::cerr << "Error: local selection context is not open.\n";
2855 return 1;
2856 }
2857 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2858 {
2859 aCtx->CloseLocalContext (Standard_False);
519d35d8 2860 }
2861
2862 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2863 anIter.More(); anIter.Next())
2864 {
d09dda09 2865 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2866 aCtx->Erase (aShape, Standard_False);
519d35d8 2867 }
2868
2869 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2870 anIter.More(); anIter.Next())
2871 {
d09dda09 2872 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2873 aCtx->Display (aShape, Standard_False);
7fd59977 2874 }
2875 return 0;
2876}
2877
8e5fb5ea 2878//! Auxiliary method to check if presentation exists
2879inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
2880 const Handle(AIS_InteractiveObject)& theIO,
2881 const Standard_Integer theMode)
c2a388f8 2882{
8e5fb5ea 2883 if (theIO.IsNull() || theCtx.IsNull())
c2a388f8 2884 {
8e5fb5ea 2885 return -1;
c2a388f8 2886 }
2887
2888 if (theMode != -1)
2889 {
2890 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2891 {
8e5fb5ea 2892 return theMode;
c2a388f8 2893 }
2894 }
2895 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2896 {
8e5fb5ea 2897 return theIO->DisplayMode();
c2a388f8 2898 }
2899 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2900 {
8e5fb5ea 2901 return theCtx->DisplayMode();
c2a388f8 2902 }
8e5fb5ea 2903
2904 return -1;
c2a388f8 2905}
2906
2907enum ViewerTest_BndAction
2908{
2909 BndAction_Hide,
2910 BndAction_Show,
2911 BndAction_Print
2912};
2913
2914//! Auxiliary method to print bounding box of presentation
8e5fb5ea 2915inline void bndPresentation (Draw_Interpretor& theDI,
2916 const Handle(PrsMgr_PresentationManager)& theMgr,
2917 const Handle(AIS_InteractiveObject)& theObj,
2918 const Standard_Integer theDispMode,
2919 const TCollection_AsciiString& theName,
2920 const ViewerTest_BndAction theAction,
2921 const Handle(Graphic3d_HighlightStyle)& theStyle)
c2a388f8 2922{
2923 switch (theAction)
2924 {
2925 case BndAction_Hide:
2926 {
8e5fb5ea 2927 theMgr->Unhighlight (theObj, theDispMode);
c2a388f8 2928 break;
2929 }
2930 case BndAction_Show:
2931 {
8e5fb5ea 2932 theMgr->Color (theObj, theStyle, theDispMode);
c2a388f8 2933 break;
2934 }
2935 case BndAction_Print:
2936 {
8e5fb5ea 2937 Bnd_Box aBox;
2938 for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
2939 {
2940 if (aPrsIter.Value().Mode() != theDispMode)
2941 continue;
2942
2943 aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
2944 }
ed063270 2945 gp_Pnt aMin = aBox.CornerMin();
2946 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 2947 theDI << theName << "\n"
ed063270 2948 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2949 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 2950 break;
2951 }
2952 }
2953}
2954
2955//==============================================================================
2956//function : VBounding
2957//purpose :
2958//==============================================================================
2959int VBounding (Draw_Interpretor& theDI,
2960 Standard_Integer theArgNb,
2961 const char** theArgVec)
2962{
2963 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2964 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2965 if (aCtx.IsNull())
2966 {
2967 std::cout << "Error: no active view!\n";
2968 return 1;
2969 }
2970
4e18052b 2971 ViewerTest_BndAction anAction = BndAction_Show;
2972 Standard_Integer aMode = -1;
c2a388f8 2973
8e5fb5ea 2974 Handle(Graphic3d_HighlightStyle) aStyle;
2975
c2a388f8 2976 Standard_Integer anArgIter = 1;
2977 for (; anArgIter < theArgNb; ++anArgIter)
2978 {
2979 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2980 anArg.LowerCase();
2981 if (anArg == "-print")
2982 {
2983 anAction = BndAction_Print;
2984 }
2985 else if (anArg == "-show")
2986 {
2987 anAction = BndAction_Show;
2988 }
2989 else if (anArg == "-hide")
2990 {
2991 anAction = BndAction_Hide;
2992 }
2993 else if (anArg == "-mode")
2994 {
2995 if (++anArgIter >= theArgNb)
2996 {
2997 std::cout << "Error: wrong syntax at " << anArg << "\n";
2998 return 1;
2999 }
3000 aMode = Draw::Atoi (theArgVec[anArgIter]);
3001 }
4e18052b 3002 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 3003 {
3004 break;
3005 }
3006 }
3007
8e5fb5ea 3008 if (anAction == BndAction_Show)
3009 aStyle = new Graphic3d_HighlightStyle (Aspect_TOHM_BOUNDBOX, Quantity_NOC_GRAY99, 0.0);
3010
3011 Standard_Integer aHighlightedMode = -1;
c2a388f8 3012 if (anArgIter < theArgNb)
3013 {
3014 // has a list of names
3015 for (; anArgIter < theArgNb; ++anArgIter)
3016 {
3017 TCollection_AsciiString aName = theArgVec[anArgIter];
3018 if (!GetMapOfAIS().IsBound2 (aName))
3019 {
3020 std::cout << "Error: presentation " << aName << " does not exist\n";
3021 return 1;
3022 }
3023
3024 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
8e5fb5ea 3025 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3026 if (aHighlightedMode == -1)
c2a388f8 3027 {
8e5fb5ea 3028 std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
c2a388f8 3029 return 1;
3030 }
8e5fb5ea 3031 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
c2a388f8 3032 }
3033 }
c3282ec1 3034 else if (aCtx->NbSelected() > 0)
c2a388f8 3035 {
3036 // remove all currently selected objects
c3282ec1 3037 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
c2a388f8 3038 {
c3282ec1 3039 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
8e5fb5ea 3040 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3041 if (aHighlightedMode != -1)
c2a388f8 3042 {
8e5fb5ea 3043 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
3044 GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
c2a388f8 3045 }
3046 }
3047 }
3048 else
3049 {
3050 // all objects
3051 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3052 anIter.More(); anIter.Next())
3053 {
3054 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
8e5fb5ea 3055 aHighlightedMode = checkMode (aCtx, anIO, aMode);
3056 if (aHighlightedMode != -1)
c2a388f8 3057 {
8e5fb5ea 3058 bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
c2a388f8 3059 }
3060 }
3061 }
c2a388f8 3062 return 0;
3063}
3064
d399d3c3 3065//==============================================================================
3066//function : VTexture
3067//purpose :
3068//==============================================================================
3069Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 3070{
d399d3c3 3071 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 3072
900f7229 3073 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 3074 if (aCommandName == "vtexture")
3075 {
3076 if (theArgsNb < 2)
7fd59977 3077 {
586db386 3078 std::cout << theArgv[0] << ": invalid arguments.\n";
d399d3c3 3079 std::cout << "Type help for more information.\n";
31160f80 3080 return 1;
7fd59977 3081 }
3082
d399d3c3 3083 // look for options of vtexture command
3084 TCollection_AsciiString aParseKey;
3085 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3086 {
3087 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 3088
d399d3c3 3089 anArg.UpperCase();
3090 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3091 {
3092 aParseKey = anArg;
3093 aParseKey.Remove (1);
3094 aParseKey.UpperCase();
900f7229 3095 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 3096 continue;
3097 }
3098
3099 if (aParseKey.IsEmpty())
3100 {
3101 continue;
3102 }
3103
900f7229 3104 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 3105 }
3106 }
3107 else if (aCommandName == "vtexscale"
3108 || aCommandName == "vtexorigin"
3109 || aCommandName == "vtexrepeat")
3110 {
3111 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3112 // equal to -scale, -origin, -repeat options of vtexture command
3113 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 3114 {
586db386 3115 std::cout << theArgv[0] << ": invalid arguments.\n";
d399d3c3 3116 std::cout << "Type help for more information.\n";
31160f80 3117 return 1;
7fd59977 3118 }
3119
900f7229 3120 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 3121 if (theArgsNb == 2)
3122 {
900f7229 3123 anArgs->Append ("OFF");
d399d3c3 3124 }
3125 else if (theArgsNb == 4)
3126 {
900f7229 3127 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3128 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 3129 }
7fd59977 3130
d399d3c3 3131 TCollection_AsciiString anArgKey;
3132 if (aCommandName == "vtexscale")
3133 {
3134 anArgKey = "SCALE";
3135 }
3136 else if (aCommandName == "vtexorigin")
3137 {
3138 anArgKey = "ORIGIN";
3139 }
3140 else
3141 {
3142 anArgKey = "REPEAT";
3143 }
3144
3145 aMapOfArgs.Bind (anArgKey, anArgs);
3146 }
3147 else if (aCommandName == "vtexdefault")
7fd59977 3148 {
d399d3c3 3149 // scan for parameters of vtexdefault command
3150 // equal to -default option of vtexture command
900f7229 3151 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 3152 }
3153
d399d3c3 3154 // Check arguments for validity
900f7229 3155 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 3156 for (; aMapIt.More(); aMapIt.Next())
3157 {
3158 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 3159 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 3160
3161 // -scale, -origin, -repeat: one argument "off", or two real values
3162 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 3163 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3164 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 3165 {
d399d3c3 3166 continue;
7fd59977 3167 }
d399d3c3 3168
3169 // -modulate: single argument "on" / "off"
900f7229 3170 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 3171 {
3172 continue;
3173 }
3174
3175 // -default: no arguments
900f7229 3176 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 3177 {
3178 continue;
3179 }
3180
3181 TCollection_AsciiString aLowerKey;
3182 aLowerKey = "-";
3183 aLowerKey += aKey;
3184 aLowerKey.LowerCase();
3185 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3186 std::cout << "Type help for more information.\n";
3187 return 1;
3188 }
3189
3190 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3191 if (anAISContext.IsNull())
3192 {
586db386 3193 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
d399d3c3 3194 return 1;
3195 }
3196
3197 Standard_Integer aPreviousMode = 0;
3198
d399d3c3 3199 TCollection_AsciiString aShapeName (theArgv[1]);
3200 Handle(AIS_InteractiveObject) anIO;
3201
3202 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3203 if (aMapOfIO.IsBound2 (aShapeName))
3204 {
3205 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3206 }
3207
3208 if (anIO.IsNull())
3209 {
3210 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3211 return 1;
3212 }
3213
3214 Handle(AIS_TexturedShape) aTexturedIO;
3215 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3216 {
3217 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3218 aPreviousMode = aTexturedIO->DisplayMode();
3219 }
7fd59977 3220 else
d399d3c3 3221 {
d399d3c3 3222 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
16420da1 3223
3224 if (anIO->HasTransformation())
3225 {
3226 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3227 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3228 }
3229
3230 anAISContext->Remove (anIO, Standard_False);
d399d3c3 3231 GetMapOfAIS().UnBind1 (anIO);
3232 GetMapOfAIS().UnBind2 (aShapeName);
3233 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3234 }
3235
3236 // -------------------------------------------
3237 // Turn texturing on/off - only for vtexture
3238 // -------------------------------------------
3239
3240 if (aCommandName == "vtexture")
3241 {
3242 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3243
3244 if (aTextureArg.IsEmpty())
7fd59977 3245 {
586db386 3246 std::cout << aCommandName << ": Texture mapping disabled.\n";
3247 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
d399d3c3 3248
3249 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3250 if (aPreviousMode == 3)
3251 {
3252 anAISContext->RecomputePrsOnly (aTexturedIO);
3253 }
3254
3255 anAISContext->Display (aTexturedIO, Standard_True);
3256 return 0;
7fd59977 3257 }
d399d3c3 3258 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3259 {
d399d3c3 3260 if (aTextureArg == "?")
3261 {
3262 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3263
586db386 3264 theDi << "\n Files in current directory : \n\n";
d399d3c3 3265 theDi.Eval ("glob -nocomplain *");
7fd59977 3266
d399d3c3 3267 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3268 aCmnd += aTextureFolder;
3269 aCmnd += "/* ";
7fd59977 3270
586db386 3271 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
d399d3c3 3272 theDi.Eval (aCmnd.ToCString());
3273 return 0;
3274 }
3275 else
3276 {
3277 aTexturedIO->SetTextureFileName (aTextureArg);
3278 }
3279 }
3280 }
7fd59977 3281
d399d3c3 3282 // ------------------------------------
3283 // Process other options and commands
3284 // ------------------------------------
7fd59977 3285
900f7229 3286 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3287 if (aMapOfArgs.Find ("DEFAULT", aValues))
3288 {
3289 aTexturedIO->SetTextureRepeat (Standard_False);
3290 aTexturedIO->SetTextureOrigin (Standard_False);
3291 aTexturedIO->SetTextureScale (Standard_False);
3292 aTexturedIO->EnableTextureModulate();
3293 }
3294 else
3295 {
3296 if (aMapOfArgs.Find ("SCALE", aValues))
3297 {
900f7229 3298 if (aValues->Value(1) != "OFF")
d399d3c3 3299 {
900f7229 3300 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3301 }
7fd59977 3302 else
d399d3c3 3303 {
3304 aTexturedIO->SetTextureScale (Standard_False);
3305 }
3306 }
7fd59977 3307
d399d3c3 3308 if (aMapOfArgs.Find ("ORIGIN", aValues))
3309 {
900f7229 3310 if (aValues->Value(1) != "OFF")
d399d3c3 3311 {
900f7229 3312 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3313 }
3314 else
3315 {
3316 aTexturedIO->SetTextureOrigin (Standard_False);
3317 }
3318 }
7fd59977 3319
d399d3c3 3320 if (aMapOfArgs.Find ("REPEAT", aValues))
3321 {
900f7229 3322 if (aValues->Value(1) != "OFF")
d399d3c3 3323 {
900f7229 3324 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3325 }
3326 else
3327 {
3328 aTexturedIO->SetTextureRepeat (Standard_False);
3329 }
7fd59977 3330 }
3331
d399d3c3 3332 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 3333 {
900f7229 3334 if (aValues->Value(1) == "ON")
d399d3c3 3335 {
3336 aTexturedIO->EnableTextureModulate();
3337 }
3338 else
3339 {
3340 aTexturedIO->DisableTextureModulate();
3341 }
7fd59977 3342 }
d399d3c3 3343 }
3344
3345 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3346 {
3347 anAISContext->RecomputePrsOnly (aTexturedIO);
3348 }
3349 else
3350 {
3351 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3352 anAISContext->Display (aTexturedIO, Standard_True);
3353 anAISContext->Update (aTexturedIO,Standard_True);
3354 }
3355
31160f80 3356 return 0;
7fd59977 3357}
3358
af65fb19 3359//! Auxiliary method to parse transformation persistence flags
3360inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
778cd667 3361 Graphic3d_TransModeFlags& theFlags)
af65fb19 3362{
778cd667 3363 if (theFlagString == "zoom")
af65fb19 3364 {
778cd667 3365 theFlags = Graphic3d_TMF_ZoomPers;
af65fb19 3366 }
3367 else if (theFlagString == "rotate")
3368 {
778cd667 3369 theFlags = Graphic3d_TMF_RotatePers;
af65fb19 3370 }
778cd667 3371 else if (theFlagString == "zoomrotate")
af65fb19 3372 {
778cd667 3373 theFlags = Graphic3d_TMF_ZoomRotatePers;
af65fb19 3374 }
778cd667 3375 else if (theFlagString == "trihedron"
3376 || theFlagString == "triedron")
af65fb19 3377 {
778cd667 3378 theFlags = Graphic3d_TMF_TriedronPers;
af65fb19 3379 }
3380 else if (theFlagString == "none")
3381 {
3382 theFlags = Graphic3d_TMF_None;
3383 }
3384 else
3385 {
3386 return Standard_False;
3387 }
3388
3389 return Standard_True;
3390}
3391
778cd667 3392//! Auxiliary method to parse transformation persistence flags
3393inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString,
3394 Aspect_TypeOfTriedronPosition& theCorner)
3395{
3396 TCollection_AsciiString aString (theString);
3397 aString.LowerCase();
3398 if (aString == "center")
3399 {
3400 theCorner = Aspect_TOTP_CENTER;
3401 }
3402 else if (aString == "top"
3403 || aString == "upper")
3404 {
3405 theCorner = Aspect_TOTP_TOP;
3406 }
3407 else if (aString == "bottom"
3408 || aString == "lower")
3409 {
3410 theCorner = Aspect_TOTP_BOTTOM;
3411 }
3412 else if (aString == "left")
3413 {
3414 theCorner = Aspect_TOTP_LEFT;
3415 }
3416 else if (aString == "right")
3417 {
3418 theCorner = Aspect_TOTP_RIGHT;
3419 }
3420 else if (aString == "topleft"
3421 || aString == "leftupper"
3422 || aString == "upperleft")
3423 {
3424 theCorner = Aspect_TOTP_LEFT_UPPER;
3425 }
3426 else if (aString == "bottomleft"
3427 || aString == "leftlower"
3428 || aString == "lowerleft")
3429 {
3430 theCorner = Aspect_TOTP_LEFT_LOWER;
3431 }
3432 else if (aString == "topright"
3433 || aString == "rightupper"
3434 || aString == "upperright")
3435 {
3436 theCorner = Aspect_TOTP_RIGHT_UPPER;
3437 }
3438 else if (aString == "bottomright"
3439 || aString == "lowerright"
3440 || aString == "rightlower")
3441 {
3442 theCorner = Aspect_TOTP_RIGHT_LOWER;
3443 }
3444 else
3445 {
3446 return Standard_False;
3447 }
3448
3449 return Standard_True;
3450}
3451
7fd59977 3452//==============================================================================
3453//function : VDisplay2
3454//author : ege
3455//purpose : Display an object from its name
7fd59977 3456//==============================================================================
519d35d8 3457static int VDisplay2 (Draw_Interpretor& theDI,
3458 Standard_Integer theArgNb,
3459 const char** theArgVec)
7fd59977 3460{
519d35d8 3461 if (theArgNb < 2)
3462 {
b6d587e3 3463 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 3464 return 1;
3465 }
b6d587e3 3466
3467 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3468 if (aCtx.IsNull())
519d35d8 3469 {
7fd59977 3470 ViewerTest::ViewerInit();
4e18052b 3471 aCtx = ViewerTest::GetAISContext();
7fd59977 3472 }
3473
b6d587e3 3474 // Parse input arguments
4e18052b 3475 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 3476 Standard_Integer isMutable = -1;
3477 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3478 Standard_Boolean toDisplayLocal = Standard_False;
3479 Standard_Boolean toReDisplay = Standard_False;
af65fb19 3480 Standard_Integer isSelectable = -1;
3481 Standard_Integer anObjDispMode = -2;
3482 Standard_Integer anObjHighMode = -2;
3483 Standard_Boolean toSetTrsfPers = Standard_False;
778cd667 3484 Handle(Graphic3d_TransformPers) aTrsfPers;
b6d587e3 3485 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 3486 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94 3487 Standard_Integer toDisplayInView = Standard_False;
519d35d8 3488 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3489 {
b7cd4ba7 3490 const TCollection_AsciiString aName = theArgVec[anArgIter];
3491 TCollection_AsciiString aNameCase = aName;
3492 aNameCase.LowerCase();
4e18052b 3493 if (anUpdateTool.parseRedrawMode (aName))
519d35d8 3494 {
3495 continue;
3496 }
b7cd4ba7 3497 else if (aNameCase == "-mutable")
3498 {
3499 isMutable = 1;
b7cd4ba7 3500 }
a1954302 3501 else if (aNameCase == "-neutral")
3502 {
3503 aDispStatus = AIS_DS_Displayed;
3504 }
3505 else if (aNameCase == "-immediate"
3506 || aNameCase == "-top")
3507 {
3508 aZLayer = Graphic3d_ZLayerId_Top;
3509 }
3510 else if (aNameCase == "-topmost")
3511 {
3512 aZLayer = Graphic3d_ZLayerId_Topmost;
3513 }
3514 else if (aNameCase == "-osd"
af65fb19 3515 || aNameCase == "-toposd"
3516 || aNameCase == "-overlay")
a1954302 3517 {
3518 aZLayer = Graphic3d_ZLayerId_TopOSD;
3519 }
af65fb19 3520 else if (aNameCase == "-botosd"
3521 || aNameCase == "-underlay")
3522 {
3523 aZLayer = Graphic3d_ZLayerId_BotOSD;
3524 }
3525 else if (aNameCase == "-select"
3526 || aNameCase == "-selectable")
3527 {
3528 isSelectable = 1;
3529 }
3530 else if (aNameCase == "-noselect"
3531 || aNameCase == "-noselection")
3532 {
3533 isSelectable = 0;
3534 }
3535 else if (aNameCase == "-dispmode"
3536 || aNameCase == "-displaymode")
3537 {
3538 if (++anArgIter >= theArgNb)
3539 {
3540 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3541 return 1;
3542 }
3543
3544 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3545 }
3546 else if (aNameCase == "-highmode"
3547 || aNameCase == "-highlightmode")
3548 {
3549 if (++anArgIter >= theArgNb)
3550 {
3551 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3552 return 1;
3553 }
3554
3555 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3556 }
3557 else if (aNameCase == "-3d")
3558 {
3559 toSetTrsfPers = Standard_True;
778cd667 3560 aTrsfPers.Nullify();
af65fb19 3561 }
778cd667 3562 else if (aNameCase == "-2d"
3563 || aNameCase == "-trihedron"
3564 || aNameCase == "-triedron")
af65fb19 3565 {
3566 toSetTrsfPers = Standard_True;
778cd667 3567 aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3568
3569 if (anArgIter + 1 < theArgNb)
3570 {
3571 Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER;
3572 if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner))
3573 {
3574 ++anArgIter;
3575 aTrsfPers->SetCorner2d (aCorner);
3576
3577 if (anArgIter + 2 < theArgNb)
3578 {
3579 TCollection_AsciiString anX (theArgVec[anArgIter + 1]);
3580 TCollection_AsciiString anY (theArgVec[anArgIter + 2]);
3581 if (anX.IsIntegerValue()
3582 && anY.IsIntegerValue())
3583 {
3584 anArgIter += 2;
3585 aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue()));
3586 }
3587 }
3588 }
3589 }
af65fb19 3590 }
af65fb19 3591 else if (aNameCase == "-trsfpers"
3592 || aNameCase == "-pers")
3593 {
778cd667 3594 if (++anArgIter >= theArgNb
3595 || !aTrsfPers.IsNull())
af65fb19 3596 {
3597 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3598 return 1;
3599 }
3600
3601 toSetTrsfPers = Standard_True;
778cd667 3602 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
af65fb19 3603 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3604 aPersFlags.LowerCase();
778cd667 3605 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
af65fb19 3606 {
778cd667 3607 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3608 return 1;
3609 }
af65fb19 3610
778cd667 3611 if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers)
3612 {
3613 aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER);
3614 }
3615 else if (aTrsfPersFlags != Graphic3d_TMF_None)
3616 {
3617 aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt());
af65fb19 3618 }
3619 }
3620 else if (aNameCase == "-trsfperspos"
3621 || aNameCase == "-perspos")
3622 {
778cd667 3623 if (anArgIter + 2 >= theArgNb
3624 || aTrsfPers.IsNull())
af65fb19 3625 {
3626 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3627 return 1;
3628 }
3629
3630 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3631 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3632 TCollection_AsciiString aZ = "0";
778cd667 3633 if (!aX.IsRealValue()
3634 || !aY.IsRealValue())
af65fb19 3635 {
3636 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3637 return 1;
3638 }
3639 if (anArgIter + 1 < theArgNb)
3640 {
3641 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
778cd667 3642 if (aTemp.IsRealValue())
af65fb19 3643 {
3644 aZ = aTemp;
3645 ++anArgIter;
3646 }
3647 }
778cd667 3648
3649 const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue());
3650 if (aTrsfPers->IsZoomOrRotate())
3651 {
3652 aTrsfPers->SetAnchorPoint (aPnt);
3653 }
3654 else if (aTrsfPers->IsTrihedronOr2d())
3655 {
3656 aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt);
3657 }
af65fb19 3658 }
a1954302 3659 else if (aNameCase == "-layer")
3660 {
3661 if (++anArgIter >= theArgNb)
3662 {
3663 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3664 return 1;
3665 }
3666
3667 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3668 if (!aValue.IsIntegerValue())
3669 {
3670 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3671 return 1;
3672 }
3673
3674 aZLayer = aValue.IntegerValue();
3675 }
a272ed94 3676 else if (aNameCase == "-view"
3677 || aNameCase == "-inview")
3678 {
3679 toDisplayInView = Standard_True;
3680 }
b6d587e3 3681 else if (aNameCase == "-local")
3682 {
a1954302 3683 aDispStatus = AIS_DS_Temporary;
b6d587e3 3684 toDisplayLocal = Standard_True;
3685 }
a1954302 3686 else if (aNameCase == "-redisplay")
3687 {
3688 toReDisplay = Standard_True;
3689 }
b6d587e3 3690 else
3691 {
3692 aNamesOfDisplayIO.Append (aName);
3693 }
3694 }
3695
3696 if (aNamesOfDisplayIO.IsEmpty())
3697 {
3698 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3699 return 1;
3700 }
3701
3702 // Prepare context for display
3703 if (toDisplayLocal && !aCtx->HasOpenedContext())
3704 {
3705 aCtx->OpenLocalContext (Standard_False);
3706 }
3707 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3708 {
3709 aCtx->CloseAllContexts (Standard_False);
3710 }
3711
3712 // Display interactive objects
3713 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3714 {
3715 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3716
3717 if (!GetMapOfAIS().IsBound2 (aName))
519d35d8 3718 {
3719 // create the AIS_Shape from a name
3720 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3721 if (!aShape.IsNull())
3722 {
b7cd4ba7 3723 if (isMutable != -1)
3724 {
3725 aShape->SetMutable (isMutable == 1);
3726 }
a1954302 3727 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3728 {
3729 aShape->SetZLayer (aZLayer);
3730 }
af65fb19 3731 if (toSetTrsfPers)
3732 {
778cd667 3733 aCtx->SetTransformPersistence (aShape, aTrsfPers);
af65fb19 3734 }
3735 if (anObjDispMode != -2)
3736 {
3737 aShape->SetDisplayMode (anObjDispMode);
3738 }
3739 if (anObjHighMode != -2)
3740 {
3741 aShape->SetHilightMode (anObjHighMode);
3742 }
b3c433fe 3743 if (!toDisplayLocal)
3744 GetMapOfAIS().Bind (aShape, aName);
a1954302 3745
3746 Standard_Integer aDispMode = aShape->HasDisplayMode()
3747 ? aShape->DisplayMode()
3748 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3749 ? aCtx->DisplayMode()
3750 : 0);
af65fb19 3751 Standard_Integer aSelMode = -1;
825aa485 3752 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
af65fb19 3753 {
c3282ec1 3754 aSelMode = aShape->GlobalSelectionMode();
af65fb19 3755 }
a1954302 3756
3757 aCtx->Display (aShape, aDispMode, aSelMode,
3758 Standard_False, aShape->AcceptShapeDecomposition(),
3759 aDispStatus);
a272ed94 3760 if (toDisplayInView)
3761 {
6a24c6de 3762 for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
a272ed94 3763 {
6a24c6de 3764 aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False);
a272ed94 3765 }
3766 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3767 }
519d35d8 3768 }
af65fb19 3769 else
3770 {
3771 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3772 }
519d35d8 3773 continue;
3774 }
7fd59977 3775
d09dda09 3776 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3777 if (isMutable != -1)
519d35d8 3778 {
d09dda09 3779 aShape->SetMutable (isMutable == 1);
3780 }
3781 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3782 {
3783 aShape->SetZLayer (aZLayer);
3784 }
3785 if (toSetTrsfPers)
3786 {
778cd667 3787 aCtx->SetTransformPersistence (aShape, aTrsfPers);
d09dda09 3788 }
3789 if (anObjDispMode != -2)
3790 {
3791 aShape->SetDisplayMode (anObjDispMode);
3792 }
3793 if (anObjHighMode != -2)
3794 {
3795 aShape->SetHilightMode (anObjHighMode);
3796 }
3797 Standard_Integer aDispMode = aShape->HasDisplayMode()
3798 ? aShape->DisplayMode()
3799 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3800 ? aCtx->DisplayMode()
3801 : 0);
3802 Standard_Integer aSelMode = -1;
825aa485 3803 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
d09dda09 3804 {
c3282ec1 3805 aSelMode = aShape->GlobalSelectionMode();
d09dda09 3806 }
3807
3808 if (aShape->Type() == AIS_KOI_Datum)
3809 {
3810 aCtx->Display (aShape, Standard_False);
3811 }
3812 else
3813 {
3814 theDI << "Display " << aName.ToCString() << "\n";
3815
3816 // update the Shape in the AIS_Shape
3817 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3818 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3819 if (!aShapePrs.IsNull())
af65fb19 3820 {
d09dda09 3821 if (!aShapePrs->Shape().IsEqual (aNewShape))
3822 {
3823 toReDisplay = Standard_True;
3824 }
3825 aShapePrs->Set (aNewShape);
af65fb19 3826 }
d09dda09 3827 if (toReDisplay)
af65fb19 3828 {
d09dda09 3829 aCtx->Redisplay (aShape, Standard_False);
af65fb19 3830 }
b7cd4ba7 3831
d09dda09 3832 if (aSelMode == -1)
519d35d8 3833 {
d09dda09 3834 aCtx->Erase (aShape);
519d35d8 3835 }
d09dda09 3836 aCtx->Display (aShape, aDispMode, aSelMode,
3837 Standard_False, aShape->AcceptShapeDecomposition(),
3838 aDispStatus);
3839 if (toDisplayInView)
519d35d8 3840 {
d09dda09 3841 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
7fd59977 3842 }
3843 }
7fd59977 3844 }
b6d587e3 3845
7fd59977 3846 return 0;
3847}
3848
f3889691 3849//===============================================================================================
3850//function : VUpdate
3851//purpose :
3852//===============================================================================================
3853static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3854{
3855 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3856 if (aContextAIS.IsNull())
3857 {
3858 std::cout << theArgVec[0] << "AIS context is not available.\n";
3859 return 1;
3860 }
3861
3862 if (theArgsNb < 2)
3863 {
3864 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3865 return 1;
3866 }
3867
3868 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3869
3870 AIS_ListOfInteractive aListOfIO;
3871
3872 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3873 {
3874 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3875
3876 Handle(AIS_InteractiveObject) anAISObj;
3877 if (anAISMap.IsBound2 (aName))
3878 {
3879 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3880 }
3881
3882 if (anAISObj.IsNull())
3883 {
3884 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3885 return 1;
3886 }
3887
3888 aListOfIO.Append (anAISObj);
3889 }
3890
3891 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3892 for (; anIOIt.More(); anIOIt.Next())
3893 {
3894 aContextAIS->Update (anIOIt.Value(), Standard_False);
3895 }
3896
3897 aContextAIS->UpdateCurrentViewer();
3898
3899 return 0;
3900}
3901
7fd59977 3902//==============================================================================
3903//function : VPerf
3904//purpose : Test the annimation of an object along a
3905// predifined trajectory
3906//Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3907//==============================================================================
3908
3909static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3910
3911 OSD_Timer myTimer;
3912 if (TheAISContext()->HasOpenedContext())
3913 TheAISContext()->CloseLocalContext();
3914
c6541a0c 3915 Standard_Real Step=4*M_PI/180;
7fd59977 3916 Standard_Real Angle=0;
3917
3918 Handle(AIS_InteractiveObject) aIO;
3919 if (GetMapOfAIS().IsBound2(argv[1]))
3920 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3921 if (aIO.IsNull())
3922 return 1;
3923
3924 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3925
3926 myTimer.Start();
3927
91322f44 3928 if (Draw::Atoi(argv[3])==1 ) {
586db386 3929 di<<" Primitives sensibles OFF\n";
7fd59977 3930 TheAISContext()->Deactivate(aIO);
3931 }
3932 else {
586db386 3933 di<<" Primitives sensibles ON\n";
7fd59977 3934 }
3935 // Movement par transformation
91322f44 3936 if(Draw::Atoi(argv[2]) ==1) {
586db386 3937 di<<" Calcul par Transformation\n";
c6541a0c 3938 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 3939
3940 Angle=Step*myAngle;
3941 gp_Trsf myTransfo;
3942 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3943 TheAISContext()->SetLocation(aShape,myTransfo);
3944 TheAISContext() ->UpdateCurrentViewer();
3945
3946 }
3947 }
3948 else {
586db386 3949 di<<" Calcul par Locations\n";
7fd59977 3950 gp_Trsf myAngleTrsf;
3951 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3952 TopLoc_Location myDeltaAngle (myAngleTrsf);
3953 TopLoc_Location myTrueLoc;
3954
c6541a0c 3955 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 3956
3957 Angle=Step*myAngle;
3958 myTrueLoc=myTrueLoc*myDeltaAngle;
3959 TheAISContext()->SetLocation(aShape,myTrueLoc );
3960 TheAISContext() ->UpdateCurrentViewer();
3961 }
3962 }
91322f44 3963 if (Draw::Atoi(argv[3])==1 ){
7fd59977 3964 // On reactive la selection des primitives sensibles
3965 TheAISContext()->Activate(aIO,0);
3966 }
3967 a3DView() -> Redraw();
3968 myTimer.Stop();
586db386 3969 di<<" Temps ecoule \n";
7fd59977 3970 myTimer.Show();
3971 return 0;
3972}
3973
7fd59977 3974//==============================================================================
3975//function : VShading
3976//purpose : Sharpen or roughten the quality of the shading
3977//Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
3978//==============================================================================
5cbef0fe
S
3979static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
3980{
7fd59977 3981 Standard_Real myDevCoef;
3982 Handle(AIS_InteractiveObject) TheAisIO;
3983
3984 // Verifications
5cbef0fe
S
3985 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
3986
7fd59977 3987 if (TheAISContext()->HasOpenedContext())
3988 TheAISContext()->CloseLocalContext();
3989
3990 if (argc < 3) {
3991 myDevCoef = 0.0008;
3992 } else {
91322f44 3993 myDevCoef =Draw::Atof(argv[2]);
7fd59977 3994 }
3995
7fd59977 3996 TCollection_AsciiString name=argv[1];
3997 if (GetMapOfAIS().IsBound2(name ))
5cbef0fe 3998 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
7fd59977 3999 if (TheAisIO.IsNull())
4000 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4001
5cbef0fe 4002 if (HaveToSet)
7fd59977 4003 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5cbef0fe 4004 else
7fd59977 4005 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4006
7fd59977 4007 TheAISContext()->Redisplay(TheAisIO);
4008 return 0;
4009}
4010//==============================================================================
4011//function : HaveMode
4012//use : VActivatedModes
4013//==============================================================================
4014#include <TColStd_ListIteratorOfListOfInteger.hxx>
4015
4016Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4017{
4018 TColStd_ListOfInteger List;
4019 TheAISContext()->ActivatedModes (TheAisIO,List);
4020 TColStd_ListIteratorOfListOfInteger it;
4021 Standard_Boolean Found=Standard_False;
4022 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4023 if (it.Value()==mode ) Found=Standard_True;
4024 }
4025 return Found;
4026}
4027
4028
4029
4030//==============================================================================
4031//function : VActivatedMode
4032//author : ege
4033//purpose : permet d'attribuer a chacune des shapes un mode d'activation
4034// (edges,vertex...)qui lui est propre et le mode de selection standard.
4035// La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4036// Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4037// qu'un nom et qu'un mode.
4038//Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4039//==============================================================================
4040#include <AIS_ListIteratorOfListOfInteractive.hxx>
4041
4042static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4043
4044{
7fd59977 4045 Standard_Boolean ThereIsName = Standard_False ;
4046
4047 if(!a3DView().IsNull()){
4048
5cbef0fe 4049 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
7fd59977 4050 // verification des arguments
4051 if (HaveToSet) {
586db386 4052 if (argc<2||argc>3) { di<<" Syntaxe error\n";return 1;}
5cbef0fe 4053 ThereIsName = (argc == 3);
7fd59977 4054 }
4055 else {
4056 // vunsetam
586db386 4057 if (argc>1) {di<<" Syntaxe error\n";return 1;}
7fd59977 4058 else {
586db386 4059 di<<" R.A.Z de tous les modes de selecion\n";
4060 di<<" Fermeture du Context local\n";
7fd59977 4061 if (TheAISContext()->HasOpenedContext())
4062 TheAISContext()->CloseLocalContext();
4063 }
7fd59977 4064 }
4065
7fd59977 4066 // IL n'y a aps de nom de shape passe en argument
4067 if (HaveToSet && !ThereIsName){
91322f44 4068 Standard_Integer aMode=Draw::Atoi(argv [1]);
7fd59977 4069
4070 const char *cmode="???";
7fd59977 4071 switch (aMode) {
4072 case 0: cmode = "Shape"; break;
4073 case 1: cmode = "Vertex"; break;
4074 case 2: cmode = "Edge"; break;
4075 case 3: cmode = "Wire"; break;
4076 case 4: cmode = "Face"; break;
4077 case 5: cmode = "Shell"; break;
4078 case 6: cmode = "Solid"; break;
4079 case 7: cmode = "Compound"; break;
4080 }
4081
4082 if( !TheAISContext()->HasOpenedContext() ) {
5cbef0fe
S
4083 // il n'y a pas de Context local d'ouvert
4084 // on en ouvre un et on charge toutes les shapes displayees
4085 // on load tous les objets displayees et on Activate les objets de la liste
4086 AIS_ListOfInteractive ListOfIO;
4087 // on sauve dans une AISListOfInteractive tous les objets currents
c3282ec1 4088 if (TheAISContext()->NbSelected()>0 ){
4089 TheAISContext()->UnhilightSelected(Standard_False);
5cbef0fe 4090
c3282ec1 4091 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4092 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
7fd59977 4093 }
4094 }
4095
4096 TheAISContext()->OpenLocalContext(Standard_False);
4097 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4098 it (GetMapOfAIS());
4099 while(it.More()){
4100 Handle(AIS_InteractiveObject) aIO =
4101 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4102 if (!aIO.IsNull())
4103 TheAISContext()->Load(aIO,0,Standard_False);
4104 it.Next();
4105 }
4106 // traitement des objets qui etaient currents dans le Contexte global
4107 if (!ListOfIO.IsEmpty() ) {
4108 // il y avait des objets currents
4109 AIS_ListIteratorOfListOfInteractive iter;
4110 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4111 Handle(AIS_InteractiveObject) aIO=iter.Value();
4112 TheAISContext()->Activate(aIO,aMode);
4113 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4114 }
4115 }
4116 else {
4117 // On applique le mode a tous les objets displayes
4118 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4119 it2 (GetMapOfAIS());
4120 while(it2.More()){
4121 Handle(AIS_InteractiveObject) aIO =
4122 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4123 if (!aIO.IsNull()) {
4124 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4125 TheAISContext()->Activate(aIO,aMode);
4126 }
4127 it2.Next();
4128 }
4129 }
4130
4131 }
4132
4133 else {
4134 // un Context local est deja ouvert
4135 // Traitement des objets du Context local
4136 if (TheAISContext()->NbSelected()>0 ){
4137 TheAISContext()->UnhilightSelected(Standard_False);
4138 // il y a des objets selected,on les parcourt
4139 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
c3282ec1 4140 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
7fd59977 4141
4142
4143 if (HaveMode(aIO,aMode) ) {
4144 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4145 TheAISContext()->Deactivate(aIO,aMode);
4146 }
4147 else{
4148 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4149 TheAISContext()->Activate(aIO,aMode);
4150 }
4151
4152 }
4153 }
4154 else{
4155 // il n'y a pas d'objets selected
4156 // tous les objets diplayes sont traites
4157 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4158 it (GetMapOfAIS());
4159 while(it.More()){
4160 Handle(AIS_InteractiveObject) aIO =
4161 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4162 if (!aIO.IsNull()) {
4163 if (HaveMode(aIO,aMode) ) {
4164 di<<" Mode: "<<cmode<<" OFF pour "
4165 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4166 TheAISContext()->Deactivate(aIO,aMode);
4167 }
4168 else{
4169 di<<" Mode: "<<cmode<<" ON pour"
4170 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4171 TheAISContext()->Activate(aIO,aMode);
4172 }
4173 }
4174 it.Next();
4175 }
4176 }
4177 }
4178 }
4179 else if (HaveToSet && ThereIsName){
91322f44 4180 Standard_Integer aMode=Draw::Atoi(argv [2]);
7fd59977 4181 Handle(AIS_InteractiveObject) aIO =
4182 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4183
4184 if (!aIO.IsNull()) {
4185 const char *cmode="???";
4186
4187 switch (aMode) {
4188 case 0: cmode = "Shape"; break;
4189 case 1: cmode = "Vertex"; break;
4190 case 2: cmode = "Edge"; break;
4191 case 3: cmode = "Wire"; break;
4192 case 4: cmode = "Face"; break;
4193 case 5: cmode = "Shell"; break;
4194 case 6: cmode = "Solid"; break;
4195 case 7: cmode = "Compound"; break;
4196 }
4197
4198 if( !TheAISContext()->HasOpenedContext() ) {
4199 TheAISContext()->OpenLocalContext(Standard_False);
4200 // On charge tous les objets de la map
4201 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4202 while(it.More()){
4203 Handle(AIS_InteractiveObject) aShape=
4204 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4205 if (!aShape.IsNull())
4206 TheAISContext()->Load(aShape,0,Standard_False);
4207 it.Next();
4208 }
4209 TheAISContext()->Activate(aIO,aMode);
4210 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4211 }
4212
4213 else {
4214 // un Context local est deja ouvert
4215 if (HaveMode(aIO,aMode) ) {
4216 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4217 TheAISContext()->Deactivate(aIO,aMode);
4218 }
4219 else{
4220 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4221 TheAISContext()->Activate(aIO,aMode);
4222 }
4223 }
4224 }
4225 }
4226 }
4227 return 0;
7fd59977 4228}
4229
cb78155f 4230//! Auxiliary method to print Interactive Object information
4231static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4232 const Handle(Standard_Transient)& theObject,
4233 Draw_Interpretor& theDI)
4234{
4235 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4236 if (anObj.IsNull())
4237 {
4238 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4239 return;
4240 }
7fd59977 4241
cb78155f 4242 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4243 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4244 << (theDetected.Contains (anObj) ? " Detected" : " ")
4245 << " Type: ";
4246 if (anObj->Type() == AIS_KOI_Datum)
4247 {
4248 // AIS_Datum
4249 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4250 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4251 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4252 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4253 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4254 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4255 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
7fd59977 4256 }
4257 // AIS_Shape
cb78155f 4258 else if (anObj->Type() == AIS_KOI_Shape
4259 && anObj->Signature() == 0)
4260 {
4261 theDI << " AIS_Shape";
7fd59977 4262 }
cb78155f 4263 else if (anObj->Type() == AIS_KOI_Relation)
4264 {
4265 // AIS_Dimention and AIS_Relation
4266 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4267 switch (aRelation->KindOfDimension())
4268 {
4269 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4270 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4271 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4272 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4273 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4274 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4275 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4276 default: theDI << " UNKNOWN dimension"; break;
4277 }
4278 }
4279 else
4280 {
4281 theDI << " UserPrs";
4282 }
4283 theDI << " (" << theObject->DynamicType()->Name() << ")";
7fd59977 4284}
4285
cb78155f 4286//! Print information about locally selected sub-shapes
23963a92 4287template <typename T>
4288static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI)
cb78155f 4289{
a9dde4a3 4290 const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext));
cb78155f 4291 TCollection_AsciiString aPrevName;
23963a92 4292 for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected())
cb78155f 4293 {
23963a92 4294 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive());
4295 const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
4296 if (aShapeIO.IsNull() || anOwner.IsNull())
4297 continue;
4298 if (isGlobalCtx)
4299 {
4300 if (anOwner == aShapeIO->GlobalSelOwner())
4301 continue;
4302 }
4303 const TopoDS_Shape aSubShape = theContext->SelectedShape();
cb78155f 4304 if (aSubShape.IsNull()
4305 || aShapeIO.IsNull()
4306 || !GetMapOfAIS().IsBound1 (aShapeIO))
4307 {
4308 continue;
4309 }
4310
4311 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4312 TopTools_MapOfShape aFilter;
4313 Standard_Integer aNumber = 0;
4314 const TopoDS_Shape aShape = aShapeIO->Shape();
4315 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4316 anIter.More(); anIter.Next())
4317 {
4318 if (!aFilter.Add (anIter.Current()))
4319 {
4320 continue; // filter duplicates
4321 }
4322
4323 ++aNumber;
4324 if (!anIter.Current().IsSame (aSubShape))
4325 {
4326 continue;
4327 }
4328
4329 Standard_CString aShapeName = NULL;
4330 switch (aSubShape.ShapeType())
4331 {
4332 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4333 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4334 case TopAbs_SOLID: aShapeName = " Solid"; break;
4335 case TopAbs_SHELL: aShapeName = " Shell"; break;
4336 case TopAbs_FACE: aShapeName = " Face"; break;
4337 case TopAbs_WIRE: aShapeName = " Wire"; break;
4338 case TopAbs_EDGE: aShapeName = " Edge"; break;
4339 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4340 default:
4341 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4342 }
4343
4344 if (aParentName != aPrevName)
4345 {
4346 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4347 aPrevName = aParentName;
4348 }
4349 theDI << " " << aShapeName << " #" << aNumber << "\n";
4350 break;
4351 }
4352 }
4353}
7fd59977 4354
4355//==============================================================================
4356//function : VState
4357//purpose :
7fd59977 4358//==============================================================================
cb78155f 4359static Standard_Integer VState (Draw_Interpretor& theDI,
4360 Standard_Integer theArgNb,
4361 Standard_CString* theArgVec)
7fd59977 4362{
cb78155f 4363 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4364 if (aCtx.IsNull())
4365 {
4366 std::cerr << "Error: No opened viewer!\n";
4367 return 1;
7fd59977 4368 }
cb78155f 4369
51023771 4370 Standard_Boolean toPrintEntities = Standard_False;
4371 Standard_Boolean toCheckSelected = Standard_False;
4372
4373 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4374 {
4375 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4376 anOption.LowerCase();
4377 if (anOption == "-detectedentities"
4378 || anOption == "-entities")
4379 {
4380 toPrintEntities = Standard_True;
4381 }
4382 else if (anOption == "-hasselected")
4383 {
4384 toCheckSelected = Standard_True;
4385 }
4386 }
4387
4388 if (toCheckSelected)
4389 {
4390 aCtx->InitSelected();
4391 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4392 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4393
4394 return 0;
4395 }
4396
4397 if (toPrintEntities)
8e7c8ccf 4398 {
4399 theDI << "Detected entities:\n";
4400 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
7479f643 4401 SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager();
aa75c0cf 4402 for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter)
8e7c8ccf 4403 {
aa75c0cf 4404 const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter);
4405 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
8e7c8ccf 4406 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4407 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
8e7c8ccf 4408 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4409 aName.LeftJustify (20, ' ');
4410 char anInfoStr[512];
f751596e 4411 Sprintf (anInfoStr,
949c9b7f 4412 " Depth: %g Distance: %g Point: %g %g %g",
aa75c0cf 4413 aPickData.Depth,
4414 aPickData.MinDist,
4415 aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z());
8e7c8ccf 4416 theDI << " " << aName
4417 << anInfoStr
4418 << " (" << anEntity->DynamicType()->Name() << ")"
4419 << "\n";
4420
4421 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4422 if (!aBRepOwner.IsNull())
4423 {
4424 theDI << " Detected Shape: "
4425 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4426 << "\n";
4427 }
4428
4429 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4430 if (!aWire.IsNull())
4431 {
4432 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4433 theDI << " Detected Child: "
4434 << aSen->DynamicType()->Name()
4435 << "\n";
4436 }
8b9a309b 4437
4438 Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity);
4439 if (!aPrimArr.IsNull())
4440 {
4441 theDI << " Detected Element: "
4442 << aPrimArr->LastDetectedElement()
4443 << "\n";
4444 }
8e7c8ccf 4445 }
4446 return 0;
4447 }
4448
cb78155f 4449 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4450 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4451 {
4452 aDetected.Add (aCtx->DetectedCurrentObject());
4453 }
4454
4455 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4456 if (theArgNb >= 2
4457 && !toShowAll)
4458 {
4459 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7fd59977 4460 {
cb78155f 4461 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4462 if (!GetMapOfAIS().IsBound2 (anObjName))
4463 {
4464 theDI << anObjName << " doesn't exist!\n";
4465 continue;
7fd59977 4466 }
4467
cb78155f 4468 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4469 TCollection_AsciiString aName = anObjName;
4470 aName.LeftJustify (20, ' ');
4471 theDI << " " << aName << " ";
4472 objInfo (aDetected, anObjTrans, theDI);
4473 theDI << "\n";
7fd59977 4474 }
cb78155f 4475 return 0;
7fd59977 4476 }
cb78155f 4477
23963a92 4478 if (!aCtx->HasOpenedContext() && aCtx->NbSelected() > 0 && !toShowAll)
cb78155f 4479 {
23963a92 4480 NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap;
c3282ec1 4481 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
cb78155f 4482 {
23963a92 4483 const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner();
4484 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
4485 // handle whole object selection
4486 if (anOwner == anObj->GlobalSelOwner())
4487 {
4488 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4489 aName.LeftJustify (20, ' ');
4490 theDI << aName << " ";
4491 objInfo (aDetected, anObj, theDI);
4492 theDI << "\n";
4493 }
7fd59977 4494 }
23963a92 4495
4496 // process selected sub-shapes
4497 printLocalSelectionInfo (aCtx, theDI);
4498
cb78155f 4499 return 0;
7fd59977 4500 }
4501
cb78155f 4502 theDI << "Neutral-point state:\n";
4503 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4504 anObjIter.More(); anObjIter.Next())
4505 {
4506 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4507 if (anObj.IsNull())
4508 {
4509 continue;
4510 }
4511
4512 TCollection_AsciiString aName = anObjIter.Key2();
4513 aName.LeftJustify (20, ' ');
4514 theDI << " " << aName << " ";
4515 objInfo (aDetected, anObj, theDI);
4516 theDI << "\n";
4517 }
23963a92 4518 printLocalSelectionInfo (aCtx, theDI);
4519 if (aCtx->HasOpenedContext())
4520 printLocalSelectionInfo (aCtx->LocalContext(), theDI);
7fd59977 4521 return 0;
4522}
4523
7fd59977 4524//=======================================================================
4525//function : PickObjects
4526//purpose :
4527//=======================================================================
4528Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4529 const AIS_KindOfInteractive TheType,
4530 const Standard_Integer TheSignature,
4531 const Standard_Integer MaxPick)
4532{
4533 Handle(AIS_InteractiveObject) IO;
4534 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4535
4536 // step 1: prepare the data
4952a30a 4537 if(curindex !=0){
7fd59977 4538 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4539 TheAISContext()->AddFilter(F1);
4540 }
4541
4542 // step 2 : wait for the selection...
76363522 4543 Standard_Integer NbPickGood (0),NbToReach(arr->Length());
7fd59977 4544 Standard_Integer NbPickFail(0);
4545 Standard_Integer argccc = 5;
4546 const char *bufff[] = { "A", "B", "C","D", "E" };
4547 const char **argvvv = (const char **) bufff;
4548
4549
4550 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4551 while(ViewerMainLoop(argccc,argvvv)){}
4552 Standard_Integer NbStored = TheAISContext()->NbSelected();
76363522 4553 if(NbStored != NbPickGood)
7fd59977 4554 NbPickGood= NbStored;
4555 else
4556 NbPickFail++;
4557 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4558 }
4559
4560 // step3 get result.
4561
76363522 4562 if (NbPickFail >= NbToReach)
4563 return Standard_False;
7fd59977 4564
4565 Standard_Integer i(0);
4566 for(TheAISContext()->InitSelected();
4567 TheAISContext()->MoreSelected();
4568 TheAISContext()->NextSelected()){
4569 i++;
4570 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4571 arr->SetValue(i,IO2);
4572 }
4573
4574
4575 if(curindex>0)
4576 TheAISContext()->CloseLocalContext(curindex);
4577
4578 return Standard_True;
4579}
4580
4581
4582//=======================================================================
4583//function : PickObject
4584//purpose :
4585//=======================================================================
4586Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4587 const Standard_Integer TheSignature,
4588 const Standard_Integer MaxPick)
4589{
4590 Handle(AIS_InteractiveObject) IO;
4591 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4592
4593 // step 1: prepare the data
4594
4952a30a 4595 if(curindex !=0){
7fd59977 4596 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4597 TheAISContext()->AddFilter(F1);
4598 }
4599
4600 // step 2 : wait for the selection...
4601 Standard_Boolean IsGood (Standard_False);
4602 Standard_Integer NbPick(0);
4603 Standard_Integer argccc = 5;
4604 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4605 const char **argvvv = (const char **) bufff;
4606
4607
4608 while(!IsGood && NbPick<= MaxPick){
4609 while(ViewerMainLoop(argccc,argvvv)){}
4610 IsGood = (TheAISContext()->NbSelected()>0) ;
4611 NbPick++;
4612 cout<<"Nb Pick :"<<NbPick<<endl;
4613 }
4614
4615
4616 // step3 get result.
4617 if(IsGood){
4618 TheAISContext()->InitSelected();
4619 IO = TheAISContext()->SelectedInteractive();
4620 }
4621
4952a30a 4622 if(curindex!=0)
7fd59977 4623 TheAISContext()->CloseLocalContext(curindex);
4624 return IO;
4625}
4626
4627//=======================================================================
4628//function : PickShape
4629//purpose : First Activate the rightmode + Put Filters to be able to
4630// pick objets that are of type <TheType>...
4631//=======================================================================
4632
4633TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4634 const Standard_Integer MaxPick)
4635{
4636
4637 // step 1: prepare the data
4638
4639 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4640 TopoDS_Shape result;
4641
4642 if(TheType==TopAbs_SHAPE){
4643 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4644 TheAISContext()->AddFilter(F1);
4645 }
4646 else{
4647 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4648 TheAISContext()->AddFilter(TF);
4649 TheAISContext()->ActivateStandardMode(TheType);
4650
4651 }
4652
4653
4654 // step 2 : wait for the selection...
4655 Standard_Boolean NoShape (Standard_True);
4656 Standard_Integer NbPick(0);
4657 Standard_Integer argccc = 5;
4658 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4659 const char **argvvv = (const char **) bufff;
4660
4661
4662 while(NoShape && NbPick<= MaxPick){
4663 while(ViewerMainLoop(argccc,argvvv)){}
4664 NoShape = (TheAISContext()->NbSelected()==0) ;
4665 NbPick++;
4666 cout<<"Nb Pick :"<<NbPick<<endl;
4667 }
4668
4669 // step3 get result.
4670
4671 if(!NoShape){
4672
4673 TheAISContext()->InitSelected();
4674 if(TheAISContext()->HasSelectedShape())
4675 result = TheAISContext()->SelectedShape();
4676 else{
4677 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
c5f3a425 4678 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
7fd59977 4679 }
4680 }
4681
4682 if(curindex>0)
4683 TheAISContext()->CloseLocalContext(curindex);
4684
4685 return result;
4686}
4687
4688
4689//=======================================================================
4690//function : PickShapes
4691//purpose :
4692//=======================================================================
4693Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4694 Handle(TopTools_HArray1OfShape)& thearr,
4695 const Standard_Integer MaxPick)
4696{
4697
4698 Standard_Integer Taille = thearr->Length();
4699 if(Taille>1)
586db386 4700 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object\n";
7fd59977 4701
4702 // step 1: prepare the data
4703 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4704 if(TheType==TopAbs_SHAPE){
4705 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4706 TheAISContext()->AddFilter(F1);
4707 }
4708 else{
4709 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4710 TheAISContext()->AddFilter(TF);
4711 TheAISContext()->ActivateStandardMode(TheType);
4712
4713 }
4714
4715 // step 2 : wait for the selection...
76363522 4716 Standard_Integer NbPickGood (0),NbToReach(thearr->Length());
7fd59977 4717 Standard_Integer NbPickFail(0);
4718 Standard_Integer argccc = 5;
4719 const char *bufff[] = { "A", "B", "C","D", "E" };
4720 const char **argvvv = (const char **) bufff;
4721
4722
4723 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4724 while(ViewerMainLoop(argccc,argvvv)){}
4725 Standard_Integer NbStored = TheAISContext()->NbSelected();
76363522 4726 if (NbStored != NbPickGood)
7fd59977 4727 NbPickGood= NbStored;
4728 else
4729 NbPickFail++;
4730 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4731 }
4732
4733 // step3 get result.
4734
76363522 4735 if (NbPickFail >= NbToReach)
4736 return Standard_False;
7fd59977 4737
4738 Standard_Integer i(0);
4739 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4740 i++;
4741 if(TheAISContext()->HasSelectedShape())
4742 thearr->SetValue(i,TheAISContext()->SelectedShape());
4743 else{
4744 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
c5f3a425 4745 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
7fd59977 4746 }
4747 }
4748
4749 TheAISContext()->CloseLocalContext(curindex);
4750 return Standard_True;
4751}
4752
4753
4754//=======================================================================
4755//function : VPickShape
4756//purpose :
4757//=======================================================================
4758static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4759{
4760 TopoDS_Shape PickSh;
4761 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4762
4763 if(argc==1)
4764 theType = TopAbs_SHAPE;
4765 else{
4766 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4767 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4768 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4769 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4770 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4771 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4772 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4773 }
4774
4775 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4776 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4777
4778 TCollection_AsciiString name;
4779
4780
4781 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4782 if(NbToPick==1){
4783 PickSh = ViewerTest::PickShape(theType);
4784
4785 if(PickSh.IsNull())
4786 return 1;
4787 if(argc>2){
4788 name += argv[2];
4789 }
4790 else{
4791
4792 if(!PickSh.IsNull()){
4793 nbOfSub[Standard_Integer(theType)]++;
4794 name += "Picked_";
4795 name += nameType[Standard_Integer(theType)];
4796 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4797 name +="_";
4798 name+=indxstring;
4799 }
4800 }
4801 // si on avait une petite methode pour voir si la shape
4802 // est deja dans la Double map, ca eviterait de creer....
4803 DBRep::Set(name.ToCString(),PickSh);
4804
4805 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4806 GetMapOfAIS().Bind(newsh, name);
4807 TheAISContext()->Display(newsh);
4808 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4809 }
4810
4811 // Plusieurs objets a picker, vite vite vite....
4812 //
4813 else{
4814 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4815 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4816 if(ViewerTest::PickShapes(theType,arr)){
4817 for(Standard_Integer i=1;i<=NbToPick;i++){
4818 PickSh = arr->Value(i);
4819 if(!PickSh.IsNull()){
4820 if(autonaming){
4821 nbOfSub[Standard_Integer(theType)]++;
4822 name.Clear();
4823 name += "Picked_";
4824 name += nameType[Standard_Integer(theType)];
4825 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4826 name +="_";
4827 name+=indxstring;
4828 }
4829 }
4830 else
4831 name = argv[1+i];
4832
4833 DBRep::Set(name.ToCString(),PickSh);
4834 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4835 GetMapOfAIS().Bind(newsh, name);
4836 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4837 TheAISContext()->Display(newsh);
4838
4839 }
4840 }
4841 }
4842 return 0;
7fd59977 4843}
7fd59977 4844
d8110103 4845//=======================================================================
4846//function : VPickSelected
4847//purpose :
4848//=======================================================================
4849static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4850{
4851 static Standard_Integer aCount = 0;
4852 TCollection_AsciiString aName = "PickedShape_";
4853
4854 if (theArgNb > 1)
4855 {
4856 aName = theArgs[1];
4857 }
4858 else
4859 {
4860 aName = aName + aCount++ + "_";
4861 }
4862
4863 Standard_Integer anIdx = 0;
4864 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4865 {
4866 TopoDS_Shape aShape;
4867 if (TheAISContext()->HasSelectedShape())
4868 {
4869 aShape = TheAISContext()->SelectedShape();
4870 }
4871 else
4872 {
4873 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
c5f3a425 4874 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
d8110103 4875 }
4876
4877 TCollection_AsciiString aCurrentName = aName;
4878 if (anIdx > 0)
4879 {
4880 aCurrentName += anIdx;
4881 }
4882
4883 DBRep::Set ((aCurrentName).ToCString(), aShape);
4884
4885 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4886 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4887 TheAISContext()->Display (aNewShape);
4888 }
4889
4890 return 0;
4891}
4892
7fd59977 4893//=======================================================================
4894//function : list of known objects
4895//purpose :
4896//=======================================================================
4897static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4898{
4899 // 1234567890 12345678901234567 123456789
4900 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4901 TCollection_AsciiString BlankLine(64,'_');
4902 Standard_Integer i ;
4903
4904 di<<"/n"<<BlankLine.ToCString()<<"\n";
4905
4906 for( i =0;i<=2;i++)
4907 Colum[i].Center(20,' ');
4908 for(i=0;i<=2;i++)
4909 di<<"|"<<Colum[i].ToCString();
586db386 4910 di<<"|\n";
7fd59977 4911
4912 di<<BlankLine.ToCString()<<"\n";
4913
4914 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4915 const char ** names = GetTypeNames();
4916
4917 TCollection_AsciiString curstring;
4918 TCollection_AsciiString curcolum[3];
4919
4920
4921 // les objets de type Datum..
4922 curcolum[1]+="Datum";
4923 for(i =0;i<=6;i++){
4924 curcolum[0].Clear();
4925 curcolum[0] += names[i];
4926
4927 curcolum[2].Clear();
4928 curcolum[2]+=TCollection_AsciiString(i+1);
4929
4930 for(Standard_Integer j =0;j<=2;j++){
4931 curcolum[j].Center(20,' ');
4932 di<<"|"<<curcolum[j].ToCString();
4933 }
586db386 4934 di<<"|\n";
7fd59977 4935 }
4936 di<<BlankLine.ToCString()<<"\n";
4937
4938 // les objets de type shape
4939 curcolum[1].Clear();
4940 curcolum[1]+="Shape";
4941 curcolum[1].Center(20,' ');
4942
4943 for(i=0;i<=2;i++){
4944 curcolum[0].Clear();
4945 curcolum[0] += names[7+i];
4946 curcolum[2].Clear();
4947 curcolum[2]+=TCollection_AsciiString(i);
4948
4949 for(Standard_Integer j =0;j<=2;j++){
4950 curcolum[j].Center(20,' ');
4951 di<<"|"<<curcolum[j].ToCString();
4952 }
586db386 4953 di<<"|\n";
7fd59977 4954 }
4955 di<<BlankLine.ToCString()<<"\n";
4956 // les IO de type objet...
4957 curcolum[1].Clear();
4958 curcolum[1]+="Object";
4959 curcolum[1].Center(20,' ');
4960 for(i=0;i<=1;i++){
4961 curcolum[0].Clear();
4962 curcolum[0] += names[10+i];
4963 curcolum[2].Clear();
4964 curcolum[2]+=TCollection_AsciiString(i);
4965
4966 for(Standard_Integer j =0;j<=2;j++){
4967 curcolum[j].Center(20,' ');
4968 di<<"|"<<curcolum[j].ToCString();
4969 }
586db386 4970 di<<"|\n";
7fd59977 4971 }
4972 di<<BlankLine.ToCString()<<"\n";
4973 // les contraintes et dimensions.
4974 // pour l'instant on separe juste contraintes et dimensions...
4975 // plus tard, on detaillera toutes les sortes...
4976 curcolum[1].Clear();
4977 curcolum[1]+="Relation";
4978 curcolum[1].Center(20,' ');
4979 for(i=0;i<=1;i++){
4980 curcolum[0].Clear();
4981 curcolum[0] += names[12+i];
4982 curcolum[2].Clear();
4983 curcolum[2]+=TCollection_AsciiString(i);
4984
4985 for(Standard_Integer j =0;j<=2;j++){
4986 curcolum[j].Center(20,' ');
4987 di<<"|"<<curcolum[j].ToCString();
4988 }
586db386 4989 di<<"|\n";
7fd59977 4990 }
4991 di<<BlankLine.ToCString()<<"\n";
4992
4993
4994 return 0;
4995}
4996
4997
4998static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
4999{
4952a30a 5000 if(argc!=2) return 1;
7fd59977 5001
5002 AIS_KindOfInteractive TheType;
5003 Standard_Integer TheSign(-1);
5004 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5005
5006
5007 AIS_ListOfInteractive LIO;
5008
5009 // en attendant l'amelioration ais pour les dimensions...
5010 //
5011 Standard_Integer dimension_status(-1);
5012 if(TheType==AIS_KOI_Relation){
5013 dimension_status = TheSign ==1 ? 1 : 0;
5014 TheSign=-1;
5015 }
5016
5017 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5018 Handle(AIS_InteractiveObject) curio;
5019 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5020 curio = it.Value();
5021
5022 if(dimension_status == -1)
5023 TheAISContext()->Erase(curio,Standard_False);
5024 else {
c5f3a425 5025 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
7fd59977 5026 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5027 (dimension_status==1 && KOD != AIS_KOD_NONE))
5028 TheAISContext()->Erase(curio,Standard_False);
5029 }
5030 }
5031 TheAISContext()->UpdateCurrentViewer();
5032 return 0;
5033}
5034static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5035{
5036 if(argc!=2) return 1;
5037
5038 AIS_KindOfInteractive TheType;
5039 Standard_Integer TheSign(-1);
5040 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5041
5042 // en attendant l'amelioration ais pour les dimensions...
5043 //
5044 Standard_Integer dimension_status(-1);
5045 if(TheType==AIS_KOI_Relation){
5046 dimension_status = TheSign ==1 ? 1 : 0;
5047 TheSign=-1;
5048 }
5049
5050 AIS_ListOfInteractive LIO;
5051 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5052 Handle(AIS_InteractiveObject) curio;
5053 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5054 curio = it.Value();
5055 if(dimension_status == -1)
5056 TheAISContext()->Display(curio,Standard_False);
5057 else {
c5f3a425 5058 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
7fd59977 5059 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5060 (dimension_status==1 && KOD != AIS_KOD_NONE))
5061 TheAISContext()->Display(curio,Standard_False);
5062 }
5063
5064 }
5065
5066 TheAISContext()->UpdateCurrentViewer();
5067 return 0;
5068}
5069
7fd59977 5070static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5071{
5072 ifstream s(a[1]);
5073 BRep_Builder builder;
5074 TopoDS_Shape shape;
5075 BRepTools::Read(shape, s, builder);
5076 DBRep::Set(a[1], shape);
5077 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5078 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5079 Ctx->Display(ais);
5080 return 0;
5081}
7fd59977 5082
189f85a3 5083//===============================================================================================
5084//function : VBsdf
5085//purpose :
5086//===============================================================================================
5087static int VBsdf (Draw_Interpretor& theDi,
5088 Standard_Integer theArgsNb,
5089 const char** theArgVec)
5090{
5091 Handle(V3d_View) aView = ViewerTest::CurrentView();
5092 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5093 if (aView.IsNull()
5094 || aViewer.IsNull())
5095 {
5096 std::cerr << "No active viewer!\n";
5097 return 1;
5098 }
5099
5100 ViewerTest_CmdParser aCmd;
5101
5102 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5103 aCmd.AddOption ("print|echo|p", "Print BSDF");
5104
5105 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5106 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5107 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5108 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5109 aCmd.AddOption ("le", "Self-emitted radiance");
5110
5111 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5112
5113 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5114 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5115 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5116
5117 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5118
5119 aCmd.Parse (theArgsNb, theArgVec);
5120
5121 if (aCmd.HasOption ("help"))
5122 {
5123 theDi.PrintHelp (theArgVec[0]);
5124 return 0;
5125 }
5126
5127 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5128
5129 // find object
5130 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5131 if (!aMap.IsBound2 (aName) )
5132 {
586db386 5133 std::cerr << "Use 'vdisplay' before\n";
189f85a3 5134 return 1;
5135 }
5136
5137 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5138 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5139 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5140
5141 if (aCmd.HasOption ("print"))
5142 {
5143 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5144
5145 std::cout << "\n"
5146 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5147 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5148 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5149 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5150 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5151 << "Fresnel: ";
5152
5153 if (aFresnel.x() >= 0.f)
5154 {
5155 std::cout
5156 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5157 }
5158 else if (aFresnel.x() >= -1.5f)
5159 {
5160 std::cout
5161 << "|Constant| " << aFresnel.z() << "\n";
5162 }
5163 else if (aFresnel.x() >= -2.5f)
5164 {
5165 std::cout
5166 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5167 }
5168 else
5169 {
5170 std::cout
5171 << "|Dielectric| " << aFresnel.y() << "\n";
5172 }
5173
5174
5175 std::cout
5176 << "Roughness: " << aBSDF.Roughness << "\n"
5177 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5178 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5179 << aBSDF.AbsorptionColor.g() << ", "
5180 << aBSDF.AbsorptionColor.b() << "\n";
5181
5182 return 0;
5183 }
5184
5185 if (aCmd.HasOption ("roughness", 1, Standard_True))
5186 {
5187 aCmd.Arg ("roughness", 0);
5188 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5189 }
5190
5191 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5192 {
5193 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5194 }
5195
5196 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5197 {
5198 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5199 }
5200
5201 if (aCmd.HasOption ("kd", 3))
5202 {
5203 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5204 }
5205 else if (aCmd.HasOption ("kd", 1, Standard_True))
5206 {
5207 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5208 }
5209
5210 if (aCmd.HasOption ("kr", 3))
5211 {
5212 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5213 }
5214 else if (aCmd.HasOption ("kr", 1, Standard_True))
5215 {
5216 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5217 }
5218
5219 if (aCmd.HasOption ("kt", 3))
5220 {
5221 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5222 }
5223 else if (aCmd.HasOption ("kt", 1, Standard_True))
5224 {
5225 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5226 }
5227
5228 if (aCmd.HasOption ("ks", 3))
5229 {
5230 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5231 }
5232 else if (aCmd.HasOption ("ks", 1, Standard_True))
5233 {
5234 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5235 }
5236
5237 if (aCmd.HasOption ("le", 3))
5238 {
5239 aBSDF.Le = aCmd.ArgVec3f ("le");
5240 }
5241 else if (aCmd.HasOption ("le", 1, Standard_True))
5242 {
5243 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5244 }
5245
5246 const std::string aFresnelErrorMessage =
5247 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5248
5249 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5250 {
5251 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5252 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5253
5254 if (aFresnelType == "schlick")
5255 {
5256 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5257 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5258 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5259 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5260 }
5261 else
5262 {
5263 std::cout << aFresnelErrorMessage;
5264 }
5265 }
5266 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5267 {
5268 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5269 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5270
5271 if (aFresnelType == "conductor")
5272 {
5273 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5274 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5275 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5276 }
5277 else
5278 {
5279 std::cout << aFresnelErrorMessage;
5280 }
5281 }
5282 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5283 {
5284 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5285 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5286
5287 if (aFresnelType == "dielectric")
5288 {
5289 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5290 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5291 }
5292 else if (aFresnelType == "constant")
5293 {
5294 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5295 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5296 }
5297 else
5298 {
5299 std::cout << aFresnelErrorMessage;
5300 }
5301 }
5302
5303 if (aCmd.HasOption ("normalize"))
5304 {
5305 aBSDF.Normalize();
5306 }
5307
5308 aMaterial.SetBSDF (aBSDF);
5309 anIObj->SetMaterial (aMaterial);
5310
5311 aView->Redraw();
5312
5313 return 0;
5314}
5315
f751596e 5316//==============================================================================
5317//function : VLoadSelection
5318//purpose : Adds given objects to map of AIS and loads selection primitives for them
5319//==============================================================================
5320static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5321 Standard_Integer theArgNb,
5322 const char** theArgVec)
5323{
5324 if (theArgNb < 2)
5325 {
5326 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5327 return 1;
5328 }
5329
5330 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5331 if (aCtx.IsNull())
5332 {
5333 ViewerTest::ViewerInit();
5334 aCtx = ViewerTest::GetAISContext();
5335 }
5336
5337 // Parse input arguments
5338 TColStd_SequenceOfAsciiString aNamesOfIO;
5339 Standard_Boolean isLocal = Standard_False;
5340 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5341 {
5342 const TCollection_AsciiString aName = theArgVec[anArgIter];
5343 TCollection_AsciiString aNameCase = aName;
5344 aNameCase.LowerCase();
5345 if (aNameCase == "-local")
5346 {
5347 isLocal = Standard_True;
5348 }
5349 else
5350 {
5351 aNamesOfIO.Append (aName);
5352 }
5353 }
5354
5355 if (aNamesOfIO.IsEmpty())
5356 {
5357 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5358 return 1;
5359 }
5360
5361 // Prepare context
5362 if (isLocal && !aCtx->HasOpenedContext())
5363 {
5364 aCtx->OpenLocalContext (Standard_False);
5365 }
5366 else if (!isLocal && aCtx->HasOpenedContext())
5367 {
5368 aCtx->CloseAllContexts (Standard_False);
5369 }
5370
5371 // Load selection of interactive objects
5372 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5373 {
5374 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5375
5b111128 5376 Handle(AIS_InteractiveObject) aShape;
5377 if (GetMapOfAIS().IsBound2 (aName))
5378 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5379 else
5380 aShape = GetAISShapeFromName (aName.ToCString());
f751596e 5381
5382 if (!aShape.IsNull())
5383 {
5384 if (!GetMapOfAIS().IsBound2 (aName))
5385 {
5386 GetMapOfAIS().Bind (aShape, aName);
5387 }
5388
5389 aCtx->Load (aShape, -1, Standard_False);
c3282ec1 5390 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
f751596e 5391 }
5392 }
5393
5394 return 0;
5395}
5396
7fd59977 5397//==============================================================================
5398//function : ViewerTest::Commands
5399//purpose : Add all the viewer command in the Draw_Interpretor
5400//==============================================================================
5401
5402void ViewerTest::Commands(Draw_Interpretor& theCommands)
5403{
5404 ViewerTest::ViewerCommands(theCommands);
5405 ViewerTest::RelationCommands(theCommands);
5406 ViewerTest::ObjectCommands(theCommands);
5407 ViewerTest::FilletCommands(theCommands);
3946774d 5408 ViewerTest::OpenGlCommands(theCommands);
7fd59977 5409
5410 const char *group = "AIS_Display";
5411
5412 // display
1c88cbaf 5413 theCommands.Add("visos",
b6d587e3 5414 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5415 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5416 __FILE__, visos, group);
7fd59977 5417
5418 theCommands.Add("vdisplay",
faea8b40 5419 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
778cd667 5420 "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]"
5421 "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]"
5422 "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft"
5423 "\n\t\t: |topRight|bottomLeft|bottomRight}"
5424 "\n\t\t: [offsetX offsetY]]]"
af65fb19 5425 "\n\t\t: [-dispMode mode] [-highMode mode]"
faea8b40 5426 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5427 "\n\t\t: [-redisplay]"
af65fb19 5428 "\n\t\t: name1 [name2] ... [name n]"
519d35d8 5429 "\n\t\t: Displays named objects."
b6d587e3 5430 "\n\t\t: Option -local enables displaying of objects in local"
5431 "\n\t\t: selection context. Local selection context will be opened"
5432 "\n\t\t: if there is not any."
778cd667 5433 "\n\t\t: -noupdate Suppresses viewer redraw call."
5434 "\n\t\t: -mutable Enables optimizations for mutable objects."
5435 "\n\t\t: -neutral Draws objects in main viewer."
5436 "\n\t\t: -layer Sets z-layer for objects."
5437 "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost"
5438 "\n\t\t: options can be used for the default z-layers."
5439 "\n\t\t: -top Draws object on top of main presentations"
5440 "\n\t\t: but below topmost."
5441 "\n\t\t: -topmost Draws in overlay for 3D presentations."
5442 "\n\t\t: with independent Depth."
5443 "\n\t\t: -overlay Draws objects in overlay for 2D presentations."
5444 "\n\t\t: (On-Screen-Display)"
5445 "\n\t\t: -underlay Draws objects in underlay for 2D presentations."
5446 "\n\t\t: (On-Screen-Display)"
5447 "\n\t\t: -selectable|-noselect Controls selection of objects."
5448 "\n\t\t: -trsfPers Sets a transform persistence flags."
5449 "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence."
5450 "\n\t\t: -2d Displays object in screen coordinates."
5451 "\n\t\t: (DY looks up)"
5452 "\n\t\t: -dispmode Sets display mode for objects."
5453 "\n\t\t: -highmode Sets hilight mode for objects."
5454 "\n\t\t: -redisplay Recomputes presentation of objects.",
b6d587e3 5455 __FILE__, VDisplay2, group);
7fd59977 5456
f3889691 5457 theCommands.Add ("vupdate",
5458 "vupdate name1 [name2] ... [name n]"
5459 "\n\t\t: Updates named objects in interactive context",
5460 __FILE__, VUpdate, group);
5461
7fd59977 5462 theCommands.Add("verase",
b6d587e3 5463 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
ac4aaa98 5464 "\n\t\t: Erases selected or named objects."
b6d587e3 5465 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5466 "\n\t\t: Option -local enables erasing of selected or named objects without"
5467 "\n\t\t: closing local selection context.",
5468 __FILE__, VErase, group);
7fd59977 5469
eef7fc64 5470 theCommands.Add("vremove",
b6d587e3 5471 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5472 "or vremove [-context] -all to remove all objects"
eef7fc64 5473 "\n\t\t: Removes selected or named objects."
5474 "\n\t\t If -context is in arguments, the objects are not deleted"
519d35d8 5475 "\n\t\t from the map of objects and names."
b6d587e3 5476 "\n\t\t: Option -local enables removing of selected or named objects without"
5477 "\n\t\t: closing local selection context. Empty local selection context will be"
5478 "\n\t\t: closed."
b7cd4ba7 5479 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5480 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
eef7fc64 5481 __FILE__, VRemove, group);
5482
7fd59977 5483 theCommands.Add("vdonly",
519d35d8 5484 "vdonly [-noupdate|-update] [name1] ... [name n]"
ac4aaa98 5485 "\n\t\t: Displays only selected or named objects",
7fd59977 5486 __FILE__,VDonly2,group);
5487
5488 theCommands.Add("vdisplayall",
b6d587e3 5489 "vidsplayall [-local]"
5490 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5491 "\n\t\t: Option -local enables displaying of the objects in local"
5492 "\n\t\t: selection context.",
5493 __FILE__, VDisplayAll, group);
7fd59977 5494
5495 theCommands.Add("veraseall",
b6d587e3 5496 "veraseall [-local]"
5497 "\n\t\t: Erases all objects displayed in the viewer."
5498 "\n\t\t: Option -local enables erasing of the objects in local"
5499 "\n\t\t: selection context.",
5500 __FILE__, VErase, group);
7fd59977 5501
5502 theCommands.Add("verasetype",
b6d587e3 5503 "verasetype <Type>"
ac4aaa98 5504 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
b6d587e3 5505 __FILE__, VEraseType, group);
c2a388f8 5506 theCommands.Add("vbounding",
5507 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5508 "\n\t\t: [-print] [-hide]"
5509 "\n\t\t: Temporarily display bounding box of specified Interactive"
5510 "\n\t\t: Objects, or print it to console if -print is specified."
5511 "\n\t\t: Already displayed box might be hidden by -hide option.",
5512 __FILE__,VBounding,group);
5513
7fd59977 5514 theCommands.Add("vdisplaytype",
5515 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5516 __FILE__,VDisplayType,group);
5517
7fd59977 5518 theCommands.Add("vsetdispmode",
ac4aaa98 5519 "vsetdispmode [name] mode(1,2,..)"
5520 "\n\t\t: Sets display mode for all, selected or named objects.",
7fd59977 5521 __FILE__,VDispMode,group);
5522
5523 theCommands.Add("vunsetdispmode",
ac4aaa98 5524 "vunsetdispmode [name]"
5525 "\n\t\t: Unsets custom display mode for selected or named objects.",
7fd59977 5526 __FILE__,VDispMode,group);
5527
5528 theCommands.Add("vdir",
ac4aaa98 5529 "Lists all objects displayed in 3D viewer",
519d35d8 5530 __FILE__,VDir,group);
7fd59977 5531
f978241f 5532#ifdef HAVE_FREEIMAGE
5533 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5534#else
5535 #define DUMP_FORMATS "{ppm}"
5536#endif
7fd59977 5537 theCommands.Add("vdump",
f978241f 5538 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5539 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5540 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
3bffef55 5541 "\n\t\t: [-tileSize Size=0]"
f978241f 5542 "\n\t\t: Dumps content of the active view into image file",
7fd59977 5543 __FILE__,VDump,group);
5544
5545 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5546 __FILE__,VSubInt,group);
5547
ad3217cd 5548 theCommands.Add("vaspects",
6262338c 5549 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
ac116c22 5550 "\n\t\t: [-setVisibility 0|1]"
5551 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5552 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5553 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5554 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5555 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6262338c 5556 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5557 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5558 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
ad3217cd 5559 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5ad8c033 5560 "\n\t\t: [-isoontriangulation 0|1]"
5561 "\n\t\t: [-setMaxParamValue {value}]"
8a1170ad 5562 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
ad3217cd 5563 "\n\t\t: Manage presentation properties of all, selected or named objects."
5564 "\n\t\t: When -subshapes is specified than following properties will be"
6262338c 5565 "\n\t\t: assigned to specified sub-shapes."
5566 "\n\t\t: When -defaults is specified than presentation properties will be"
5567 "\n\t\t: assigned to all objects that have not their own specified properties"
5568 "\n\t\t: and to all objects to be displayed in the future."
5569 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
ad3217cd 5570 __FILE__,VAspects,group);
5571
7fd59977 5572 theCommands.Add("vsetcolor",
ad3217cd 5573 "vsetcolor [-noupdate|-update] [name] ColorName"
5574 "\n\t\t: Sets color for all, selected or named objects."
5575 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5576 __FILE__,VAspects,group);
7fd59977 5577
5578 theCommands.Add("vunsetcolor",
ad3217cd 5579 "vunsetcolor [-noupdate|-update] [name]"
5580 "\n\t\t: Resets color for all, selected or named objects."
5581 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5582 __FILE__,VAspects,group);
7fd59977 5583
5584 theCommands.Add("vsettransparency",
ad3217cd 5585 "vsettransparency [-noupdate|-update] [name] Coefficient"
ac4aaa98 5586 "\n\t\t: Sets transparency for all, selected or named objects."
ad3217cd 5587 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5588 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5589 __FILE__,VAspects,group);
7fd59977 5590
5591 theCommands.Add("vunsettransparency",
ad3217cd 5592 "vunsettransparency [-noupdate|-update] [name]"
5593 "\n\t\t: Resets transparency for all, selected or named objects."
5594 "\n\t\t: Alias for vaspects -unsettransp [name].",
5595 __FILE__,VAspects,group);
7fd59977 5596
5597 theCommands.Add("vsetmaterial",
ad3217cd 5598 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5599 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5600 __FILE__,VAspects,group);
7fd59977 5601
5602 theCommands.Add("vunsetmaterial",
ad3217cd 5603 "vunsetmaterial [-noupdate|-update] [name]"
5604 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5605 __FILE__,VAspects,group);
7fd59977 5606
5607 theCommands.Add("vsetwidth",
ad3217cd 5608 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5609 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5610 __FILE__,VAspects,group);
7fd59977 5611
5612 theCommands.Add("vunsetwidth",
ad3217cd 5613 "vunsetwidth [-noupdate|-update] [name]"
5614 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5615 __FILE__,VAspects,group);
7fd59977 5616
99c56d44 5617 theCommands.Add("vsetinteriorstyle",
ad3217cd 5618 "vsetinteriorstyle [-noupdate|-update] [name] style"
5619 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5620 __FILE__,VSetInteriorStyle,group);
99c56d44 5621
7fd59977 5622 theCommands.Add("vsensdis",
faea8b40 5623 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5624 "\n\t\t: Standard entity types are those defined in Select3D package:"
5625 "\n\t\t: - sensitive box"
5626 "\n\t\t: - sensitive face"
5627 "\n\t\t: - sensitive curve"
5628 "\n\t\t: - sensitive segment"
5629 "\n\t\t: - sensitive circle"
5630 "\n\t\t: - sensitive point"
5631 "\n\t\t: - sensitive triangulation"
5632 "\n\t\t: - sensitive triangle"
5633 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5634 __FILE__,VDispSensi,group);
5635
7fd59977 5636 theCommands.Add("vsensera",
faea8b40 5637 "vsensera : erase active entities",
5638 __FILE__,VClearSensi,group);
7fd59977 5639
5640 theCommands.Add("vperf",
faea8b40 5641 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5642 "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5643 __FILE__,VPerf,group);
7fd59977 5644
7fd59977 5645 theCommands.Add("vsetshading",
faea8b40 5646 "vsetshading : vsetshading name Quality(default=0.0008) "
f2139a7f 5647 "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.",
faea8b40 5648 __FILE__,VShading,group);
7fd59977 5649
5650 theCommands.Add("vunsetshading",
faea8b40 5651 "vunsetshading :vunsetshading name "
f2139a7f 5652 "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.",
faea8b40 5653 __FILE__,VShading,group);
7fd59977 5654
d399d3c3 5655 theCommands.Add ("vtexture",
5656 "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n"
5657 " [-scale u v] [-scale off]\n"
5658 " [-origin u v] [-origin off]\n"
5659 " [-repeat u v] [-repeat off]\n"
5660 " [-modulate {on | off}]"
5661 " [-default]'\n"
5662 " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n"
5663 " specifying one of the predefined textures.\n"
5664 " The options are: \n"
5665 " -scale u v : enable texture scaling and set scale factors\n"
5666 " -scale off : disable texture scaling\n"
5667 " -origin u v : enable texture origin positioning and set the origin\n"
5668 " -origin off : disable texture origin positioning\n"
5669 " -repeat u v : enable texture repeat and set texture coordinate scaling\n"
5670 " -repeat off : disable texture repeat\n"
5671 " -modulate {on | off} : enable or disable texture modulation\n"
5672 " -default : sets texture mapping default parameters\n"
5673 "or 'vtexture NameOfShape' if you want to disable texture mapping\n"
5674 "or 'vtexture NameOfShape ?' to list available textures\n",
5675 __FILE__, VTexture, group);
7fd59977 5676
5677 theCommands.Add("vtexscale",
5678 "'vtexscale NameOfShape ScaleU ScaleV' \n \
5679 or 'vtexscale NameOfShape ScaleUV' \n \
5680 or 'vtexscale NameOfShape' to disable scaling\n ",
5681 __FILE__,VTexture,group);
5682
5683 theCommands.Add("vtexorigin",
5684 "'vtexorigin NameOfShape UOrigin VOrigin' \n \
5685 or 'vtexorigin NameOfShape UVOrigin' \n \
5686 or 'vtexorigin NameOfShape' to disable origin positioning\n ",
5687 __FILE__,VTexture,group);
5688
5689 theCommands.Add("vtexrepeat",
5690 "'vtexrepeat NameOfShape URepeat VRepeat' \n \
5691 or 'vtexrepeat NameOfShape UVRepeat \n \
5692 or 'vtexrepeat NameOfShape' to disable texture repeat \n ",
5693 VTexture,group);
5694
5695 theCommands.Add("vtexdefault",
5696 "'vtexdefault NameOfShape' to set texture mapping default parameters \n",
5697 VTexture,group);
5698
5699 theCommands.Add("vsetam",
faea8b40 5700 "vsetam [shapename] mode"
5701 "\n\t\t: Activates selection mode for all selected or named shapes."
5702 "\n\t\t: Mod can be:"
5703 "\n\t\t: 0 - for shape itself"
5704 "\n\t\t: 1 - vertices"
5705 "\n\t\t: 2 - edges"
5706 "\n\t\t: 3 - wires"
5707 "\n\t\t: 4 - faces"
5708 "\n\t\t: 5 - shells"
5709 "\n\t\t: 6 - solids"
5710 "\n\t\t: 7 - compounds"
5711 __FILE__,VActivatedMode,group);
7fd59977 5712
5713 theCommands.Add("vunsetam",
faea8b40 5714 "vunsetam : Deactivates all selection modes for all shapes.",
5715 __FILE__,VActivatedMode,group);
7fd59977 5716
ac4aaa98 5717 theCommands.Add("vstate",
51023771 5718 "vstate [-entities] [-hasSelected] [name1] ... [nameN]"
8e7c8ccf 5719 "\n\t\t: Reports show/hidden state for selected or named objects"
51023771 5720 "\n\t\t: -entities - print low-level information about detected entities"
5721 "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise",
7fd59977 5722 __FILE__,VState,group);
5723
5724 theCommands.Add("vpickshapes",
5725 "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]",
5726 __FILE__,VPickShape,group);
5727
5728 theCommands.Add("vtypes",
5729 "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters",
5730 VIOTypes,group);
5731
faea8b40 5732 theCommands.Add("vr",
5733 "vr filename"
5734 "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ",
7fd59977 5735 __FILE__,vr, group);
5736
d8110103 5737 theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.",
5738 __FILE__, VPickSelected, group);
5739
f751596e 5740 theCommands.Add ("vloadselection",
5741 "vloadselection [-context] [name1] ... [nameN] : allows to load selection"
5742 "\n\t\t: primitives for the shapes with names given without displaying them."
5743 "\n\t\t: -local - open local context before selection computation",
5744 __FILE__, VLoadSelection, group);
5745
189f85a3 5746 theCommands.Add("vbsdf", "vbsdf [name] [options]"
5747 "\nAdjusts parameters of material BSDF:"
5748 "\n -help : Shows this message"
5749 "\n -print : Print BSDF"
5750 "\n -kd : Weight of the Lambertian BRDF"
5751 "\n -kr : Weight of the reflection BRDF"
5752 "\n -kt : Weight of the transmission BTDF"
5753 "\n -ks : Weight of the glossy Blinn BRDF"
5754 "\n -le : Self-emitted radiance"
5755 "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x,"
5756 "\n Schlick x y z, Dielectric x, Conductor x y"
5757 "\n -roughness : Roughness of material (Blinn's exponent)"
5758 "\n -absorpcoeff : Absorption coefficient (only for transparent material)"
5759 "\n -absorpcolor : Absorption color (only for transparent material)"
5760 "\n -normalize : Normalize BSDF coefficients",
5761 __FILE__, VBsdf, group);
5762
7fd59977 5763}
5764
5765//=====================================================================
5766//========================= for testing Draft and Rib =================
5767//=====================================================================
5768#include <BRepOffsetAPI_MakeThickSolid.hxx>
5769#include <DBRep.hxx>
5770#include <TopoDS_Face.hxx>
5771#include <gp_Pln.hxx>
5772#include <AIS_KindOfSurface.hxx>
5773#include <BRepOffsetAPI_DraftAngle.hxx>
5774#include <Precision.hxx>
5775#include <BRepAlgo.hxx>
5776#include <OSD_Environment.hxx>
5777#include <DrawTrSurf.hxx>
5778//#include <DbgTools.hxx>
5779//#include <FeatAlgo_MakeLinearForm.hxx>
5780
5781
5782
5783
5784//=======================================================================
5785//function : IsValid
5786//purpose :
5787//=======================================================================
5788static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs,
5789 const TopoDS_Shape& theResult,
5790 const Standard_Boolean closedSolid,
5791 const Standard_Boolean GeomCtrl)
5792{
5793 OSD_Environment check ("DONT_SWITCH_IS_VALID") ;
5794 TCollection_AsciiString checkValid = check.Value();
5795 Standard_Boolean ToCheck = Standard_True;
5796 if (!checkValid.IsEmpty()) {
0797d9d3 5797#ifdef OCCT_DEBUG
7fd59977 5798 cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n";
5799#endif
5800 if ( checkValid=="true" || checkValid=="TRUE" ) {
5801 ToCheck= Standard_False;
5802 }
5803 } else {
0797d9d3 5804#ifdef OCCT_DEBUG
586db386 5805 cout <<"DONT_SWITCH_IS_VALID non positionne\n";
7fd59977 5806#endif
5807 }
5808 Standard_Boolean IsValid = Standard_True;
5809 if (ToCheck)
5810 IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ;
5811 return IsValid;
5812
5813}
5814
5815//===============================================================================
5816// TDraft : test draft, uses AIS Viewer
5817// Solid Face Plane Angle Reverse
5818//===============================================================================
5819static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
5820{
5821 if (argc < 5) return 1;
5822// argv[1] - TopoDS_Shape Solid
5823// argv[2] - TopoDS_Shape Face
5824// argv[3] - TopoDS_Shape Plane
5825// argv[4] - Standard_Real Angle
5826// argv[5] - Standard_Integer Reverse
5827
91322f44 5828// Sprintf(prefix, argv[1]);
7fd59977 5829 Standard_Real anAngle = 0;
5830 Standard_Boolean Rev = Standard_False;
5831 Standard_Integer rev = 0;
5832 TopoDS_Shape Solid = GetShapeFromName(argv[1]);
5833 TopoDS_Shape face = GetShapeFromName(argv[2]);
5834 TopoDS_Face Face = TopoDS::Face(face);
5835 TopoDS_Shape Plane = GetShapeFromName(argv[3]);
5836 if (Plane.IsNull ()) {
586db386 5837 di << "TEST : Plane is NULL\n";
7fd59977 5838 return 1;
5839 }
91322f44 5840 anAngle = Draw::Atof(argv[4]);
c6541a0c 5841 anAngle = 2*M_PI * anAngle / 360.0;
7fd59977 5842 gp_Pln aPln;
5843 Handle( Geom_Surface )aSurf;
5844 AIS_KindOfSurface aSurfType;
5845 Standard_Real Offset;
5846 gp_Dir aDir;
5847 if(argc > 4) { // == 5
91322f44 5848 rev = Draw::Atoi(argv[5]);
7fd59977 5849 Rev = (rev)? Standard_True : Standard_False;
5850 }
5851
5852 TopoDS_Face face2 = TopoDS::Face(Plane);
5853 if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset))
5854 {
586db386 5855 di << "TEST : Can't find plane\n";
7fd59977 5856 return 1;
5857 }
5858
5859 aDir = aPln.Axis().Direction();
5860 if (!aPln.Direct())
5861 aDir.Reverse();
5862 if (Plane.Orientation() == TopAbs_REVERSED)
5863 aDir.Reverse();
5864 di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n";
5865
5866 BRepOffsetAPI_DraftAngle Draft (Solid);
5867
5868 if(Abs(anAngle)< Precision::Angular()) {
586db386 5869 di << "TEST : NULL angle\n";
7fd59977 5870 return 1;}
5871
5872 if(Rev) anAngle = - anAngle;
5873 Draft.Add (Face, aDir, anAngle, aPln);
5874 Draft.Build ();
5875 if (!Draft.IsDone()) {
586db386 5876 di << "TEST : Draft Not DONE \n";
7fd59977 5877 return 1;
5878 }
5879 TopTools_ListOfShape Larg;
5880 Larg.Append(Solid);
5881 if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) {
586db386 5882 di << "TEST : DesignAlgo returns Not valid\n";
7fd59977 5883 return 1;
5884 }
5885
5886 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5887 Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape());
5888
5889 if ( !ais.IsNull() ) {
5890 ais->SetColor(DEFAULT_COLOR);
5891 ais->SetMaterial(DEFAULT_MATERIAL);
5892 // Display the AIS_Shape without redraw
5893 Ctx->Display(ais, Standard_False);
5894
5895 const char *Name = "draft1";
5896 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name);
5897 if (IsBound) {
5898 Handle(AIS_InteractiveObject) an_object =
5899 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name));
5900 if (!an_object.IsNull()) {
5901 Ctx->Remove(an_object,
5902 Standard_True) ;
5903 GetMapOfAIS().UnBind2(Name) ;
5904 }
5905 }
5906 GetMapOfAIS().Bind(ais, Name);
5907// DBRep::Set("draft", ais->Shape());
5908 }
5909 Ctx->Display(ais, Standard_True);
5910 return 0;
5911}
5912
1d7ca641 5913//==============================================================================
5914//function : splitParameter
197ac94e 5915//purpose : Split parameter string to parameter name and parameter value
1d7ca641 5916//==============================================================================
5917Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString,
5918 TCollection_AsciiString& theName,
5919 TCollection_AsciiString& theValue)
5920{
5921 Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length());
5922
5923 if (aParamNameEnd == 0)
5924 {
5925 return Standard_False;
5926 }
5927
5928 TCollection_AsciiString aString (theString);
5929 if (aParamNameEnd != 0)
5930 {
5931 theValue = aString.Split (aParamNameEnd);
5932 aString.Split (aString.Length() - 1);
5933 theName = aString;
5934 }
7fd59977 5935
1d7ca641 5936 return Standard_True;
5937}
7fd59977 5938
5939//============================================================================
5940// MyCommands
5941//============================================================================
5942void ViewerTest::MyCommands( Draw_Interpretor& theCommands)
5943{
5944
5945 DrawTrSurf::BasicCommands(theCommands);
5946 const char* group = "Check Features Operations commands";
5947
5948 theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse",
5949 __FILE__,
5950 &TDraft,group); //Draft_Modification
5951}
5952
5953//==============================================================================
5954// ViewerTest::Factory
5955//==============================================================================
5956void ViewerTest::Factory(Draw_Interpretor& theDI)
5957{
5958 // definition of Viewer Command
128cc8df 5959 ViewerTest::Commands(theDI);
128cc8df 5960
0797d9d3 5961#ifdef OCCT_DEBUG
586db386 5962 theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n";
7fd59977 5963#endif
5964}
5965
5966// Declare entry point PLUGINFACTORY
5967DPLUGIN(ViewerTest)