0026691: CMake building procedure should support compiler of version 14.0 of Microsof...
[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>
66#include <SelectMgr_EntityOwner.hxx>
67#include <StdSelect_BRepOwner.hxx>
68#include <StdSelect_ViewerSelector3d.hxx>
cb78155f 69#include <TopTools_MapOfShape.hxx>
4e18052b 70#include <ViewerTest_AutoUpdater.hxx>
7fd59977 71
7fd59977 72#include <stdio.h>
7fd59977 73
74#include <Draw_Interpretor.hxx>
75#include <TCollection_AsciiString.hxx>
76#include <Draw_PluginMacro.hxx>
7fd59977 77
78// avoid warnings on 'extern "C"' functions returning C++ classes
79#ifdef WNT
80#define _CRT_SECURE_NO_DEPRECATE
81#pragma warning(4:4190)
82#pragma warning (disable:4996)
83#endif
84
7fd59977 85extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
86
7fd59977 87#include <Quantity_Color.hxx>
88#include <Quantity_NameOfColor.hxx>
89
90#include <Graphic3d_NameOfMaterial.hxx>
91
6262338c 92#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
94#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
7fd59977 95
792c785c 96//=======================================================================
97//function : GetColorFromName
98//purpose : get the Quantity_NameOfColor from a string
99//=======================================================================
7fd59977 100
792c785c 101Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
102{
8316c618 103 Quantity_NameOfColor aColor = DEFAULT_COLOR;
104 Quantity_Color::ColorFromName (theName, aColor);
105 return aColor;
7fd59977 106}
107
536d98e2 108//=======================================================================
109//function : ParseColor
110//purpose :
111//=======================================================================
112
113Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
114 const char** theArgVec,
115 Quantity_Color& theColor)
116{
117 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
118 if (theArgNb >= 1
119 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
120 {
121 theColor = aColor;
122 return 1;
123 }
124 else if (theArgNb >= 3)
125 {
126 const TCollection_AsciiString anRgbStr[3] =
127 {
128 theArgVec[0],
129 theArgVec[1],
130 theArgVec[2]
131 };
132 if (!anRgbStr[0].IsRealValue()
133 || !anRgbStr[1].IsRealValue()
134 || !anRgbStr[2].IsRealValue())
135 {
136 return 0;
137 }
138
139 Graphic3d_Vec4d anRgb;
140 anRgb.x() = anRgbStr[0].RealValue();
141 anRgb.y() = anRgbStr[1].RealValue();
142 anRgb.z() = anRgbStr[2].RealValue();
143 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
144 || anRgb.y() < 0.0 || anRgb.y() > 1.0
145 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
146 {
147 std::cout << "Error: RGB color values should be within range 0..1!\n";
148 return 0;
149 }
150
151 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
152 return 3;
153 }
154
155 return 0;
156}
157
7fd59977 158//=======================================================================
159//function : GetTypeNames
160//purpose :
161//=======================================================================
162static const char** GetTypeNames()
163{
164 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
165 "Shape","ConnectedShape","MultiConn.Shape",
166 "ConnectedInter.","MultiConn.",
167 "Constraint","Dimension"};
168 static const char** ThePointer = names;
169 return ThePointer;
170}
171
172//=======================================================================
173//function : GetTypeAndSignfromString
174//purpose :
175//=======================================================================
176void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
177{
178 const char ** thefullnames = GetTypeNames();
179 Standard_Integer index(-1);
180
181 for(Standard_Integer i=0;i<=13 && index==-1;i++)
182 if(!strcasecmp(name,thefullnames[i]))
183 index = i;
184
185 if(index ==-1){
186 TheType = AIS_KOI_None;
187 TheSign = -1;
188 return;
189 }
190
191 if(index<=6){
192 TheType = AIS_KOI_Datum;
193 TheSign = index+1;
194 }
195 else if (index <=9){
196 TheType = AIS_KOI_Shape;
197 TheSign = index-7;
198 }
199 else if(index<=11){
200 TheType = AIS_KOI_Object;
201 TheSign = index-10;
202 }
203 else{
204 TheType = AIS_KOI_Relation;
205 TheSign = index-12;
206 }
207
208}
209
210
211
212#include <string.h>
213#include <Draw_Interpretor.hxx>
214#include <Draw.hxx>
215#include <Draw_Appli.hxx>
216#include <DBRep.hxx>
217
218
219#include <TCollection_AsciiString.hxx>
220#include <V3d_Viewer.hxx>
221#include <V3d_View.hxx>
222#include <V3d.hxx>
223
224#include <AIS_InteractiveContext.hxx>
225#include <AIS_Shape.hxx>
226#include <AIS_TexturedShape.hxx>
227#include <AIS_DisplayMode.hxx>
228#include <TColStd_MapOfInteger.hxx>
229#include <AIS_MapOfInteractive.hxx>
230#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
231#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
232#include <ViewerTest_EventManager.hxx>
233
234#include <TopoDS_Solid.hxx>
235#include <BRepTools.hxx>
236#include <BRep_Builder.hxx>
237#include <TopAbs_ShapeEnum.hxx>
238
239#include <TopoDS.hxx>
240#include <BRep_Tool.hxx>
241
242
243#include <Draw_Window.hxx>
244#include <AIS_ListIteratorOfListOfInteractive.hxx>
245#include <AIS_ListOfInteractive.hxx>
246#include <AIS_DisplayMode.hxx>
247#include <TopTools_ListOfShape.hxx>
248#include <BRepOffsetAPI_MakeThickSolid.hxx>
249#include <BRepOffset.hxx>
250
7fd59977 251//==============================================================================
252// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
253//==============================================================================
254Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
255 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
256 return TheMap;
257}
258
29e2c6d2 259//=======================================================================
260//function : Display
261//purpose :
262//=======================================================================
263Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
264 const Handle(AIS_InteractiveObject)& theObject,
265 const Standard_Boolean theToUpdate,
266 const Standard_Boolean theReplaceIfExists)
9558a876
A
267{
268 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29e2c6d2 269 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
270 if (aCtx.IsNull())
9558a876 271 {
29e2c6d2 272 std::cout << "Error: AIS context is not available.\n";
9558a876
A
273 return Standard_False;
274 }
275
276 if (aMap.IsBound2 (theName))
277 {
278 if (!theReplaceIfExists)
279 {
29e2c6d2 280 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
9558a876
A
281 << "Please use another name.\n";
282 return Standard_False;
283 }
284
29e2c6d2 285 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
9558a876 286 if (!anOldObj.IsNull())
29e2c6d2 287 {
288 aCtx->Remove (anOldObj, Standard_True);
289 }
9558a876
A
290 aMap.UnBind2 (theName);
291 }
292
29e2c6d2 293 if (theObject.IsNull())
208e6839 294 {
29e2c6d2 295 // object with specified name has been already unbound
208e6839 296 return Standard_True;
297 }
298
29e2c6d2 299 // unbind AIS object if it was bound with another name
300 aMap.UnBind1 (theObject);
9558a876
A
301
302 // can be registered without rebinding
29e2c6d2 303 aMap.Bind (theObject, theName);
304 aCtx->Display (theObject, theToUpdate);
9558a876
A
305 return Standard_True;
306}
307
29e2c6d2 308//! Alias for ViewerTest::Display(), compatibility with old code.
309Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
310 const Handle(AIS_InteractiveObject)& theObject,
311 Standard_Boolean theReplaceIfExists = Standard_True)
312{
313 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
314}
315
7fd59977 316static TColStd_MapOfInteger theactivatedmodes(8);
317static TColStd_ListOfTransient theEventMgrs;
318
d09dda09 319static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
7fd59977 320 const Handle(AIS_InteractiveContext)& Ctx)
321{
322 theEventMgrs.Clear();
323 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
324}
325
24de79c3 326static Handle(V3d_View)& a3DView()
327{
7fd59977 328 static Handle(V3d_View) Viou;
329 return Viou;
330}
331
24de79c3 332
7fd59977 333Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
334 static Handle(AIS_InteractiveContext) aContext;
335 return aContext;
336}
337
24de79c3 338const Handle(V3d_View)& ViewerTest::CurrentView()
7fd59977 339{
340 return a3DView();
341}
342void ViewerTest::CurrentView(const Handle(V3d_View)& V)
343{
344 a3DView() = V;
345}
346
24de79c3 347const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
7fd59977 348{
349 return TheAISContext();
350}
351
352void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
353{
354 TheAISContext() = aCtx;
355 ViewerTest::ResetEventManager();
356}
357
358Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
359{
4952a30a 360 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 361}
362
363Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
364{
4952a30a 365 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 366}
367
368
369void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
370 theEventMgrs.Prepend(EM);
371}
372
373void ViewerTest::UnsetEventManager()
374{
375 theEventMgrs.RemoveFirst();
376}
377
378
379void ViewerTest::ResetEventManager()
380{
d09dda09 381 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 382 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
383}
384
385Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
386{
387 Handle(ViewerTest_EventManager) EM;
388 if(theEventMgrs.IsEmpty()) return EM;
389 Handle(Standard_Transient) Tr = theEventMgrs.First();
c5f3a425 390 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
7fd59977 391 return EM;
392}
393
7fd59977 394//=======================================================================
34db9c00 395//function : Get Context and active view
7fd59977 396//purpose :
397//=======================================================================
34db9c00 398static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
399 Handle(V3d_View)& theView)
7fd59977 400{
34db9c00 401 theCtx = ViewerTest::GetAISContext();
402 theView = ViewerTest::CurrentView();
403 if (theCtx.IsNull()
404 || theView.IsNull())
7fd59977 405 {
34db9c00 406 std::cout << "Error: cannot find an active view!\n";
407 return Standard_False;
7fd59977 408 }
34db9c00 409 return Standard_True;
7fd59977 410}
411
7fd59977 412//==============================================================================
413//function : GetShapeFromName
414//purpose : Compute an Shape from a draw variable or a file name
415//==============================================================================
416
417static TopoDS_Shape GetShapeFromName(const char* name)
418{
419 TopoDS_Shape S = DBRep::Get(name);
420
421 if ( S.IsNull() ) {
422 BRep_Builder aBuilder;
423 BRepTools::Read( S, name, aBuilder);
424 }
425
426 return S;
427}
4e18e72a 428
7fd59977 429//==============================================================================
430//function : GetAISShapeFromName
431//purpose : Compute an AIS_Shape from a draw variable or a file name
432//==============================================================================
433Handle(AIS_Shape) GetAISShapeFromName(const char* name)
434{
435 Handle(AIS_Shape) retsh;
436
437 if(GetMapOfAIS().IsBound2(name)){
438 const Handle(AIS_InteractiveObject) IO =
439 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
440 if (!IO.IsNull()) {
eafb234b 441 if(IO->Type()==AIS_KOI_Shape) {
7fd59977 442 if(IO->Signature()==0){
c5f3a425 443 retsh = Handle(AIS_Shape)::DownCast (IO);
7fd59977 444 }
445 else
446 cout << "an Object which is not an AIS_Shape "
447 "already has this name!!!"<<endl;
eafb234b 448 }
7fd59977 449 }
450 return retsh;
451 }
452
453
454 TopoDS_Shape S = GetShapeFromName(name);
455 if ( !S.IsNull() ) {
456 retsh = new AIS_Shape(S);
457 }
458 return retsh;
459}
460
461
462//==============================================================================
463//function : Clear
464//purpose : Remove all the object from the viewer
465//==============================================================================
466void ViewerTest::Clear()
467{
468 if ( !a3DView().IsNull() ) {
469 if (TheAISContext()->HasOpenedContext())
470 TheAISContext()->CloseLocalContext();
471 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
472 while ( it.More() ) {
473 cout << "Remove " << it.Key2() << endl;
d09dda09 474 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
475 TheAISContext()->Remove(anObj,Standard_False);
7fd59977 476 it.Next();
477 }
f751596e 478 TheAISContext()->RebuildSelectionStructs();
7fd59977 479 TheAISContext()->UpdateCurrentViewer();
7fd59977 480 GetMapOfAIS().Clear();
481 }
482}
483
484//==============================================================================
485//function : StandardModesActivation
486//purpose : Activate a selection mode, vertex, edge, wire ..., in a local
487// Context
488//==============================================================================
489void ViewerTest::StandardModeActivation(const Standard_Integer mode )
490{
491 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
492 if(mode==0) {
493 if (TheAISContext()->HasOpenedContext())
494 aContext->CloseLocalContext();
495 } else {
496
497 if(!aContext->HasOpenedContext()) {
498 // To unhilight the preselected object
c3282ec1 499 aContext->UnhilightSelected(Standard_False);
7fd59977 500 // Open a local Context in order to be able to select subshape from
501 // the selected shape if any or for all if there is no selection
c3282ec1 502 if (!aContext->FirstSelectedObject().IsNull()){
7fd59977 503 aContext->OpenLocalContext(Standard_False);
504
c3282ec1 505 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
506 aContext->Load( aContext->SelectedInteractive(),-1,Standard_True);
7fd59977 507 }
508 }
509 else
510 aContext->OpenLocalContext();
511 }
512
513 const char *cmode="???";
514
515 switch (mode) {
516 case 0: cmode = "Shape"; break;
517 case 1: cmode = "Vertex"; break;
518 case 2: cmode = "Edge"; break;
519 case 3: cmode = "Wire"; break;
520 case 4: cmode = "Face"; break;
521 case 5: cmode = "Shell"; break;
522 case 6: cmode = "Solid"; break;
4754e164 523 case 7: cmode = "Compsolid"; break;
524 case 8: cmode = "Compound"; break;
7fd59977 525 }
526
527 if(theactivatedmodes.Contains(mode))
528 { // Desactivate
529 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
530 theactivatedmodes.Remove(mode);
531 cout<<"Mode "<< cmode <<" OFF"<<endl;
532 }
533 else
534 { // Activate
535 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
536 theactivatedmodes.Add(mode);
537 cout<<"Mode "<< cmode << " ON" << endl;
538 }
539 }
540}
541
1c88cbaf 542//==============================================================================
543//function : CopyIsoAspect
544//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
545//==============================================================================
546static Handle(Prs3d_IsoAspect) CopyIsoAspect
547 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
548 const Standard_Integer theNbIsos)
549{
550 Quantity_Color aColor;
551 Aspect_TypeOfLine aType;
552 Standard_Real aWidth;
553
554 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
555
556 Handle(Prs3d_IsoAspect) aResult =
557 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
558
559 return aResult;
560}
561
562//==============================================================================
563//function : visos
564//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
565//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
566//==============================================================================
567static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
568{
569 if (TheAISContext().IsNull()) {
570 di << argv[0] << " Call 'vinit' before!\n";
571 return 1;
572 }
573
574 if (argc <= 1) {
575 di << "Current number of isos : " <<
576 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
577 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
578 di << "IsoOnPlane mode is " <<
579 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
5ad8c033 580 di << "IsoOnTriangulation mode is " <<
581 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
1c88cbaf 582 return 0;
583 }
584
585 Standard_Integer aLastInd = argc - 1;
586 Standard_Boolean isChanged = Standard_False;
1d47d8d0 587 Standard_Integer aNbUIsos = 0;
588 Standard_Integer aNbVIsos = 0;
1c88cbaf 589
590 if (aLastInd >= 3) {
591 Standard_Boolean isIsoOnPlane = Standard_False;
592
593 if (strcmp(argv[aLastInd], "1") == 0) {
594 isIsoOnPlane = Standard_True;
595 isChanged = Standard_True;
596 } else if (strcmp(argv[aLastInd], "0") == 0) {
597 isIsoOnPlane = Standard_False;
598 isChanged = Standard_True;
599 }
600
601 if (isChanged) {
602 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
603 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
604 aLastInd -= 3;
605
606 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
607 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
608
609 TheAISContext()->IsoOnPlane(isIsoOnPlane);
610
611 if (aLastInd == 0) {
612 // If there are no shapes provided set the default numbers.
613 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
614 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
615 }
616 }
617 }
618
619 Standard_Integer i;
620
621 for (i = 1; i <= aLastInd; i++) {
622 TCollection_AsciiString name(argv[i]);
623 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
624
625 if (IsBound) {
626 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
627 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
628 const Handle(AIS_InteractiveObject) aShape =
629 Handle(AIS_InteractiveObject)::DownCast (anObj);
6262338c 630 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
1c88cbaf 631 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
632 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
633
634 if (isChanged) {
635 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
636 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
637 TheAISContext()->SetLocalAttributes
638 (aShape, CurDrawer, Standard_False);
639 TheAISContext()->Redisplay(aShape);
640 } else {
641 di << "Number of isos for " << argv[i] << " : "
642 << aUIso->Number() << " " << aVIso->Number() << "\n";
643 }
644 } else {
645 di << argv[i] << ": Not an AIS interactive object!\n";
646 }
647 } else {
648 di << argv[i] << ": Use 'vdisplay' before\n";
649 }
650 }
651
652 if (isChanged) {
653 TheAISContext()->UpdateCurrentViewer();
654 }
655
656 return 0;
657}
658
34db9c00 659static Standard_Integer VDispSensi (Draw_Interpretor& ,
660 Standard_Integer theArgNb,
661 Standard_CString* )
7fd59977 662{
34db9c00 663 if (theArgNb > 1)
664 {
665 std::cout << "Error: wrong syntax!\n";
666 return 1;
667 }
668
669 Handle(AIS_InteractiveContext) aCtx;
670 Handle(V3d_View) aView;
671 if (!getCtxAndView (aCtx, aView))
672 {
673 return 1;
674 }
675
676 aCtx->DisplayActiveSensitive (aView);
7fd59977 677 return 0;
678
679}
34db9c00 680
681static Standard_Integer VClearSensi (Draw_Interpretor& ,
682 Standard_Integer theArgNb,
683 Standard_CString* )
7fd59977 684{
34db9c00 685 if (theArgNb > 1)
686 {
687 std::cout << "Error: wrong syntax!\n";
688 return 1;
689 }
690
691 Handle(AIS_InteractiveContext) aCtx;
692 Handle(V3d_View) aView;
693 if (!getCtxAndView (aCtx, aView))
694 {
695 return 1;
696 }
697 aCtx->ClearActiveSensitive (aView);
7fd59977 698 return 0;
699}
700
701//==============================================================================
519d35d8 702//function : VDir
7fd59977 703//purpose : To list the displayed object with their attributes
7fd59977 704//==============================================================================
519d35d8 705static int VDir (Draw_Interpretor& theDI,
706 Standard_Integer ,
707 const char** )
708{
709 if (!a3DView().IsNull())
710 {
711 return 0;
7fd59977 712 }
713
519d35d8 714 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
715 anIter.More(); anIter.Next())
716 {
717 theDI << "\t" << anIter.Key2().ToCString() << "\n";
718 }
7fd59977 719 return 0;
720}
721
3c982548 722//==============================================================================
723//function : VSelPrecision
f751596e 724//purpose : To set the selection tolerance value
725//Draw arg : Selection tolerance value (real value determining the width and
726// height of selecting frustum bases). Without arguments the function
727// just prints current tolerance.
3c982548 728//==============================================================================
729static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
730{
f751596e 731 if( argc > 2 )
3c982548 732 {
28ee613b 733 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
3c982548 734 return 1;
735 }
736
737 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
738 if( aContext.IsNull() )
739 return 1;
740
741 if( argc == 1 )
742 {
f751596e 743 Standard_Real aPixelTolerance = aContext->PixelTolerance();
f751596e 744 di << "Pixel tolerance : " << aPixelTolerance << "\n";
3c982548 745 }
f751596e 746 else if (argc == 2)
3c982548 747 {
28ee613b 748 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
749 anArg.LowerCase();
750 if (anArg == "-unset")
751 {
3bf9a45f 752 aContext->SetPixelTolerance (-1);
28ee613b 753 }
754 else
755 {
3bf9a45f 756 aContext->SetPixelTolerance (anArg.IntegerValue());
28ee613b 757 }
3c982548 758 }
f751596e 759
3c982548 760 return 0;
761}
762
f978241f 763//! Auxiliary enumeration
764enum ViewerTest_StereoPair
765{
766 ViewerTest_SP_Single,
767 ViewerTest_SP_SideBySide,
768 ViewerTest_SP_OverUnder
769};
770
7fd59977 771//==============================================================================
772//function : VDump
773//purpose : To dump the active view snapshot to image file
7fd59977 774//==============================================================================
34db9c00 775static Standard_Integer VDump (Draw_Interpretor& theDI,
776 Standard_Integer theArgNb,
777 Standard_CString* theArgVec)
7fd59977 778{
34db9c00 779 if (theArgNb < 2)
7fd59977 780 {
34db9c00 781 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
7fd59977 782 return 1;
783 }
784
34db9c00 785 Standard_Integer anArgIter = 1;
786 Standard_CString aFilePath = theArgVec[anArgIter++];
787 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
788 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
f978241f 789 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
34db9c00 790 Standard_Integer aWidth = 0;
791 Standard_Integer aHeight = 0;
792 for (; anArgIter < theArgNb; ++anArgIter)
7fd59977 793 {
34db9c00 794 TCollection_AsciiString anArg (theArgVec[anArgIter]);
795 anArg.LowerCase();
f978241f 796 if (anArg == "-buffer")
7fd59977 797 {
f978241f 798 if (++anArgIter >= theArgNb)
799 {
800 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
801 return 1;
802 }
803
804 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
805 aBufArg.LowerCase();
806 if (aBufArg == "rgba")
807 {
808 aBufferType = Graphic3d_BT_RGBA;
809 }
810 else if (aBufArg == "rgb")
811 {
812 aBufferType = Graphic3d_BT_RGB;
813 }
814 else if (aBufArg == "depth")
815 {
816 aBufferType = Graphic3d_BT_Depth;
817 }
818 else
819 {
820 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
821 return 1;
822 }
7fd59977 823 }
f978241f 824 else if (anArg == "-stereo")
7fd59977 825 {
f978241f 826 if (++anArgIter >= theArgNb)
827 {
828 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
829 return 1;
830 }
831
832 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
833 aStereoArg.LowerCase();
834 if (aStereoArg == "l"
835 || aStereoArg == "left")
836 {
837 aStereoOpts = V3d_SDO_LEFT_EYE;
838 }
839 else if (aStereoArg == "r"
840 || aStereoArg == "right")
841 {
842 aStereoOpts = V3d_SDO_RIGHT_EYE;
843 }
844 else if (aStereoArg == "mono")
845 {
846 aStereoOpts = V3d_SDO_MONO;
847 }
848 else if (aStereoArg == "blended"
849 || aStereoArg == "blend"
850 || aStereoArg == "stereo")
851 {
852 aStereoOpts = V3d_SDO_BLENDED;
853 }
854 else if (aStereoArg == "sbs"
855 || aStereoArg == "sidebyside")
856 {
857 aStereoPair = ViewerTest_SP_SideBySide;
858 }
859 else if (aStereoArg == "ou"
860 || aStereoArg == "overunder")
861 {
862 aStereoPair = ViewerTest_SP_OverUnder;
863 }
864 else
865 {
866 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
867 return 1;
868 }
7fd59977 869 }
f978241f 870 else if (anArg == "-rgba"
871 || anArg == "rgba")
34db9c00 872 {
f978241f 873 aBufferType = Graphic3d_BT_RGBA;
34db9c00 874 }
f978241f 875 else if (anArg == "-rgb"
876 || anArg == "rgb")
34db9c00 877 {
f978241f 878 aBufferType = Graphic3d_BT_RGB;
34db9c00 879 }
f978241f 880 else if (anArg == "-depth"
881 || anArg == "depth")
34db9c00 882 {
f978241f 883 aBufferType = Graphic3d_BT_Depth;
34db9c00 884 }
f978241f 885
886 else if (anArg == "-width"
887 || anArg == "width"
888 || anArg == "sizex")
34db9c00 889 {
f978241f 890 if (aWidth != 0)
34db9c00 891 {
892 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
893 return 1;
894 }
895 else if (++anArgIter >= theArgNb)
896 {
897 std::cout << "Error: integer value is expected right after 'width'\n";
898 return 1;
899 }
900 aWidth = Draw::Atoi (theArgVec[anArgIter]);
901 }
f978241f 902 else if (anArg == "-height"
903 || anArg == "height"
904 || anArg == "-sizey")
34db9c00 905 {
906 if (aHeight != 0)
907 {
908 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
909 return 1;
910 }
34db9c00 911 else if (++anArgIter >= theArgNb)
912 {
f978241f 913 std::cout << "Error: integer value is expected right after 'height'\n";
34db9c00 914 return 1;
915 }
34db9c00 916 aHeight = Draw::Atoi (theArgVec[anArgIter]);
917 }
918 else
919 {
920 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
921 return 1;
922 }
7fd59977 923 }
34db9c00 924 if ((aWidth <= 0 && aHeight > 0)
925 || (aWidth > 0 && aHeight <= 0))
7fd59977 926 {
34db9c00 927 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
85e096c3 928 return 1;
929 }
930
34db9c00 931 Handle(V3d_View) aView = ViewerTest::CurrentView();
932 if (aView.IsNull())
85e096c3 933 {
34db9c00 934 std::cout << "Error: cannot find an active view!\n";
935 return 1;
7fd59977 936 }
85e096c3 937
34db9c00 938 if (aWidth <= 0 || aHeight <= 0)
b5ac8292 939 {
f978241f 940 aView->Window()->Size (aWidth, aHeight);
941 }
942
943 Image_AlienPixMap aPixMap;
944
945 bool isBigEndian = Image_PixMap::IsBigEndianHost();
946 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
947 switch (aBufferType)
948 {
949 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
950 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
951 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
952 }
953
954 switch (aStereoPair)
955 {
956 case ViewerTest_SP_Single:
b5ac8292 957 {
f978241f 958 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
959 {
960 theDI << "Fail: view dump failed!\n";
961 return 0;
962 }
963 else if (aPixMap.SizeX() != Standard_Size(aWidth)
964 || aPixMap.SizeY() != Standard_Size(aHeight))
965 {
966 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
967 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
968 }
969 break;
b5ac8292 970 }
f978241f 971 case ViewerTest_SP_SideBySide:
b5ac8292 972 {
f978241f 973 if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
974 {
975 theDI << "Fail: not enough memory for image allocation!\n";
976 return 0;
977 }
978
979 Image_PixMap aPixMapL, aPixMapR;
980 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
981 aWidth, aHeight, aPixMap.SizeRowBytes());
982 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
983 aWidth, aHeight, aPixMap.SizeRowBytes());
984 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
985 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
986 )
34db9c00 987 {
988 theDI << "Fail: view dump failed!\n";
f978241f 989 return 0;
34db9c00 990 }
f978241f 991 break;
b5ac8292 992 }
f978241f 993 case ViewerTest_SP_OverUnder:
994 {
995 if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
996 {
997 theDI << "Fail: not enough memory for image allocation!\n";
998 return 0;
999 }
b5ac8292 1000
f978241f 1001 Image_PixMap aPixMapL, aPixMapR;
1002 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
1003 aWidth, aHeight, aPixMap.SizeRowBytes());
1004 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
1005 aWidth, aHeight, aPixMap.SizeRowBytes());
1006 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1007 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
1008 {
1009 theDI << "Fail: view dump failed!\n";
1010 return 0;
1011 }
1012 break;
1013 }
7fd59977 1014 }
85e096c3 1015
34db9c00 1016 if (!aPixMap.Save (aFilePath))
85e096c3 1017 {
34db9c00 1018 theDI << "Fail: image can not be saved!\n";
85e096c3 1019 }
1020 return 0;
7fd59977 1021}
1022
7fd59977 1023//==============================================================================
1024//function : Displays,Erase...
1025//purpose :
1026//Draw arg :
1027//==============================================================================
1028static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
1029 const Standard_Integer Mode,
1030 const Standard_Integer TypeOfOperation,
1031 const Standard_Boolean Upd)
1032{
1033 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1034
1035 switch(TypeOfOperation){
1036 case 1:
1037 Ctx->Display(IO,Mode,Upd);
1038 break;
1039 case 2:{
eb4320f2 1040 Ctx->Erase(IO,Upd);
7fd59977 1041 break;
1042 }
1043 case 3:{
1044 if(IO.IsNull())
1045 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
1046 else
1047 Ctx->SetDisplayMode(IO,Mode,Upd);
1048 break;
1049 }
1050 case 4:{
1051 if(IO.IsNull())
1052 Ctx->SetDisplayMode(0,Upd);
1053 else
1054 Ctx->UnsetDisplayMode(IO,Upd);
1055 break;
1056 }
1057 }
1058 return 0;
1059}
1060
1061//=======================================================================
1062//function :
1063//purpose :
1064//=======================================================================
1065static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1066{
1067
1068 TCollection_AsciiString name;
1069 if(argc>3)
1070 return 1;
1071 // display others presentations
1072 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1073 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1074 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1075 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1076
1077 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1078
1079 //unset displaymode.. comportement particulier...
1080 if(TypeOfOperation==4){
1081 if(argc==1){
c3282ec1 1082 if(Ctx->NbSelected()==0){
7fd59977 1083 Handle(AIS_InteractiveObject) IO;
1084 VwrTst_DispErase(IO,-1,4,Standard_False);
1085 }
7fd59977 1086 else{
1087 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
c3282ec1 1088 VwrTst_DispErase(Ctx->SelectedInteractive(),-1,4,Standard_False);}
7fd59977 1089 Ctx->UpdateCurrentViewer();
1090 }
1091 else{
1092 Handle(AIS_InteractiveObject) IO;
1093 name = argv[1];
1094 if(GetMapOfAIS().IsBound2(name)){
1095 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1096 if (!IO.IsNull())
1097 VwrTst_DispErase(IO,-1,4,Standard_True);
1098 }
1099 }
1100 }
1101 else if(argc==2){
91322f44 1102 Standard_Integer Dmode = Draw::Atoi(argv[1]);
c3282ec1 1103 if(Ctx->NbSelected()==0 && TypeOfOperation==3){
7fd59977 1104 Handle(AIS_InteractiveObject) IO;
1105 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1106 }
1107 if(!Ctx->HasOpenedContext()){
1108 // set/unset display mode sur le Contexte...
c3282ec1 1109 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1110 VwrTst_DispErase(Ctx->SelectedInteractive(),Dmode,TypeOfOperation,Standard_False);
7fd59977 1111 }
1112 Ctx->UpdateCurrentViewer();
1113 }
1114 else{
1115 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
c3282ec1 1116 Ctx->Display(Ctx->SelectedInteractive(),Dmode);
7fd59977 1117 }
1118 }
1119 else{
1120 Handle(AIS_InteractiveObject) IO;
1121 name = argv[1];
1122 if(GetMapOfAIS().IsBound2(name))
1123 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1124 if (!IO.IsNull())
91322f44 1125 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
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);
2277 aCtx->Remove (aShapePrs, Standard_False);
2278 GetMapOfAIS().UnBind2 (aName);
2279 GetMapOfAIS().Bind (aColoredPrs, aName);
2280 toDisplay = Standard_True;
2281 aShapePrs = aColoredPrs;
2282 aPrs = aColoredPrs;
2283 }
2284 }
99c56d44 2285
ad3217cd 2286 if (!aPrs.IsNull())
2287 {
2288 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2289 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2290 if (aChangeSet->ToSetVisibility == 1)
2291 {
2292 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2293 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2294 }
2295 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2296 {
2297 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2298 }
2299 else if (aChangeSet->ToSetMaterial == -1)
2300 {
2301 aCtx->UnsetMaterial (aPrs, Standard_False);
2302 }
2303 if (aChangeSet->ToSetColor == 1)
2304 {
2305 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2306 }
2307 else if (aChangeSet->ToSetColor == -1)
2308 {
2309 aCtx->UnsetColor (aPrs, Standard_False);
2310 }
2311 if (aChangeSet->ToSetTransparency == 1)
2312 {
2313 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2314 }
2315 else if (aChangeSet->ToSetTransparency == -1)
2316 {
2317 aCtx->UnsetTransparency (aPrs, Standard_False);
2318 }
2319 if (aChangeSet->ToSetLineWidth == 1)
2320 {
2321 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2322 }
2323 else if (aChangeSet->ToSetLineWidth == -1)
2324 {
2325 aCtx->UnsetWidth (aPrs, Standard_False);
2326 }
5ad8c033 2327 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2328 {
2329 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2330 toRedisplay = Standard_True;
2331 }
8a1170ad 2332 else if (aChangeSet->ToSetSensitivity != 0)
2333 {
2334 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2335 }
6262338c 2336 if (!aDrawer.IsNull())
2337 {
2338 if (aChangeSet->ToSetShowFreeBoundary == 1)
2339 {
2340 aDrawer->SetFreeBoundaryDraw (Standard_True);
2341 toRedisplay = Standard_True;
2342 }
2343 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2344 {
2345 aDrawer->SetFreeBoundaryDraw (Standard_False);
2346 toRedisplay = Standard_True;
2347 }
2348 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2349 {
2350 Handle(Prs3d_LineAspect) aBoundaryAspect =
2351 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2352 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2353 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2354 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2355 toRedisplay = Standard_True;
2356 }
2357 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2358 {
2359 Handle(Prs3d_LineAspect) aBoundaryAspect =
2360 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2361 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2362 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2363 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2364 toRedisplay = Standard_True;
2365 }
ac116c22 2366 if (aChangeSet->ToSetTypeOfLine != 0)
2367 {
2368 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2369 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2370 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2371 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2372 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2373 toRedisplay = Standard_True;
2374 }
5ad8c033 2375 if (aChangeSet->ToSetMaxParamValue != 0)
2376 {
2377 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2378 }
6262338c 2379 }
99c56d44 2380
ad3217cd 2381 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2382 {
2383 aChangeSet = &aChangesIter.ChangeValue();
2384 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2385 aSubShapeIter.More(); aSubShapeIter.Next())
2386 {
2387 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2388 if (aChangeSet->ToSetVisibility == 1)
2389 {
2390 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2391 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2392 }
ad3217cd 2393 if (aChangeSet->ToSetColor == 1)
2394 {
2395 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2396 }
2397 if (aChangeSet->ToSetLineWidth == 1)
2398 {
2399 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2400 }
2401 if (aChangeSet->ToSetColor == -1
2402 || aChangeSet->ToSetLineWidth == -1)
2403 {
2404 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2405 }
5ad8c033 2406 if (aChangeSet->ToSetMaxParamValue != 0)
2407 {
2408 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2409 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2410 }
8a1170ad 2411 if (aChangeSet->ToSetSensitivity != 0)
2412 {
2413 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2414 }
ad3217cd 2415 }
2416 }
2417 if (toDisplay)
2418 {
2419 aCtx->Display (aPrs, Standard_False);
2420 }
6262338c 2421 if (toRedisplay)
2422 {
2423 aCtx->Redisplay (aPrs, Standard_False);
2424 }
ad3217cd 2425 else if (!aColoredPrs.IsNull())
2426 {
36132a2e 2427 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2428 }
99c56d44 2429 }
ad3217cd 2430 }
99c56d44 2431 return 0;
2432}
2433
7fd59977 2434//==============================================================================
2435//function : VDonly2
2436//author : ege
2437//purpose : Display only a selected or named object
519d35d8 2438// if there is no selected or named object s, nothing is done
7fd59977 2439//==============================================================================
519d35d8 2440static int VDonly2 (Draw_Interpretor& ,
2441 Standard_Integer theArgNb,
2442 const char** theArgVec)
7fd59977 2443{
519d35d8 2444 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2445 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2446 if (aCtx.IsNull())
2447 {
2448 std::cerr << "Error: no active view!\n";
7fd59977 2449 return 1;
519d35d8 2450 }
7fd59977 2451
519d35d8 2452 if (aCtx->HasOpenedContext())
2453 {
2454 aCtx->CloseLocalContext();
2455 }
7fd59977 2456
519d35d8 2457 Standard_Integer anArgIter = 1;
2458 for (; anArgIter < theArgNb; ++anArgIter)
2459 {
4e18052b 2460 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2461 {
2462 break;
2463 }
2464 }
7fd59977 2465
519d35d8 2466 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2467 if (anArgIter >= theArgNb)
2468 {
2469 // display only selected objects
c3282ec1 2470 if (aCtx->NbSelected() < 1)
519d35d8 2471 {
2472 return 0;
7fd59977 2473 }
2474
c3282ec1 2475 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
519d35d8 2476 {
c3282ec1 2477 aDispSet.Add (aCtx->SelectedInteractive());
519d35d8 2478 }
2479 }
2480 else
2481 {
2482 // display only specified objects
2483 for (; anArgIter < theArgNb; ++anArgIter)
2484 {
2485 TCollection_AsciiString aName = theArgVec[anArgIter];
2486 if (GetMapOfAIS().IsBound2 (aName))
2487 {
d09dda09 2488 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2489 if (!aShape.IsNull())
519d35d8 2490 {
519d35d8 2491 aCtx->Display (aShape, Standard_False);
d09dda09 2492 aDispSet.Add (aShape);
519d35d8 2493 }
7fd59977 2494 }
2495 }
7fd59977 2496 }
519d35d8 2497
2498 // weed out other objects
2499 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2500 {
2501 if (aDispSet.Contains (anIter.Key1()))
2502 {
2503 continue;
2504 }
2505
d09dda09 2506 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2507 if (aShape.IsNull())
519d35d8 2508 {
519d35d8 2509 aCtx->Erase (aShape, Standard_False);
2510 }
519d35d8 2511 }
7fd59977 2512 return 0;
2513}
2514
eef7fc64 2515//==============================================================================
2516//function : VRemove
2517//purpose : Removes selected or named objects.
2518// If there is no selected or named objects,
2519// all objects in the viewer can be removed with argument -all.
2520// If -context is in arguments, the object is not deleted from the map of
2521// objects (deleted only from the current context).
2522//==============================================================================
2523int VRemove (Draw_Interpretor& theDI,
519d35d8 2524 Standard_Integer theArgNb,
2525 const char** theArgVec)
eef7fc64 2526{
4e18052b 2527 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2528 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2529 if (aCtx.IsNull())
eef7fc64 2530 {
b6d587e3 2531 std::cerr << "Error: no active view!\n";
eef7fc64 2532 return 1;
2533 }
2534
4e18052b 2535 Standard_Boolean isContextOnly = Standard_False;
2536 Standard_Boolean toRemoveAll = Standard_False;
2537 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2538 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2539
2540 Standard_Integer anArgIter = 1;
2541 for (; anArgIter < theArgNb; ++anArgIter)
2542 {
2543 TCollection_AsciiString anArg = theArgVec[anArgIter];
2544 anArg.LowerCase();
2545 if (anArg == "-context")
2546 {
2547 isContextOnly = Standard_True;
2548 }
2549 else if (anArg == "-all")
2550 {
2551 toRemoveAll = Standard_True;
2552 }
b7cd4ba7 2553 else if (anArg == "-noinfo")
2554 {
2555 toPrintInfo = Standard_False;
2556 }
b6d587e3 2557 else if (anArg == "-local")
2558 {
2559 toRemoveLocal = Standard_True;
2560 }
2561 else if (anUpdateTool.parseRedrawMode (anArg))
2562 {
2563 continue;
2564 }
2565 else
519d35d8 2566 {
2567 break;
2568 }
2569 }
2570 if (toRemoveAll
2571 && anArgIter < theArgNb)
2572 {
b6d587e3 2573 std::cerr << "Error: wrong syntax!\n";
2574 return 1;
2575 }
2576
2577 if (toRemoveLocal && !aCtx->HasOpenedContext())
2578 {
2579 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2580 return 1;
2581 }
b6d587e3 2582 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2583 {
2584 aCtx->CloseAllContexts (Standard_False);
2585 }
519d35d8 2586
eef7fc64 2587 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2588 if (toRemoveAll)
eef7fc64 2589 {
2590 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2591 anIter.More(); anIter.Next())
2592 {
2593 anIONameList.Append (anIter.Key2());
2594 }
2595 }
519d35d8 2596 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2597 {
519d35d8 2598 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2599 {
519d35d8 2600 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2601 if (!GetMapOfAIS().IsBound2 (aName))
2602 {
2603 theDI << aName.ToCString() << " was not bound to some object.\n";
2604 continue;
2605 }
2606
d09dda09 2607 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2608 if (anIO->GetContext() != aCtx)
eef7fc64 2609 {
d09dda09 2610 theDI << aName.ToCString() << " was not displayed in current context.\n";
2611 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 2612 continue;
2613 }
2614
d09dda09 2615 anIONameList.Append (aName);
2616 continue;
eef7fc64 2617 }
2618 }
c3282ec1 2619 else if (aCtx->NbSelected() > 0)
eef7fc64 2620 {
2621 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2622 anIter.More(); anIter.Next())
2623 {
2624 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
c3282ec1 2625 if (!aCtx->IsSelected (anIO))
eef7fc64 2626 {
eef7fc64 2627 continue;
2628 }
2629
d09dda09 2630 anIONameList.Append (anIter.Key2());
2631 continue;
eef7fc64 2632 }
2633 }
2634
2635 // Unbind all removed objects from the map of displayed IO.
2636 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2637 anIter.More(); anIter.Next())
2638 {
519d35d8 2639 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
d09dda09 2640 aCtx->Remove (anIO, Standard_False);
2641 if (toPrintInfo)
519d35d8 2642 {
d09dda09 2643 theDI << anIter.Value().ToCString() << " was removed\n";
519d35d8 2644 }
519d35d8 2645 if (!isContextOnly)
2646 {
2647 GetMapOfAIS().UnBind2 (anIter.Value());
2648 }
2649 }
b6d587e3 2650
2651 // Close local context if it is empty
2652 TColStd_MapOfTransient aLocalIO;
2653 if (aCtx->HasOpenedContext()
2654 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2655 {
2656 aCtx->CloseAllContexts (Standard_False);
2657 }
2658
eef7fc64 2659 return 0;
2660}
2661
7fd59977 2662//==============================================================================
b514beda 2663//function : VErase
2664//purpose : Erase some selected or named objects
7fd59977 2665// if there is no selected or named objects, the whole viewer is erased
7fd59977 2666//==============================================================================
b514beda 2667int VErase (Draw_Interpretor& theDI,
2668 Standard_Integer theArgNb,
2669 const char** theArgVec)
7fd59977 2670{
a1954302 2671 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2672 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2673 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2674 if (aCtx.IsNull())
b514beda 2675 {
b6d587e3 2676 std::cerr << "Error: no active view!\n";
7fd59977 2677 return 1;
b514beda 2678 }
519d35d8 2679
519d35d8 2680 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2681
2682 Standard_Integer anArgIter = 1;
a272ed94 2683 Standard_Boolean toEraseLocal = Standard_False;
2684 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2685 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2686 for (; anArgIter < theArgNb; ++anArgIter)
2687 {
b6d587e3 2688 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2689 anArgCase.LowerCase();
2690 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2691 {
b6d587e3 2692 continue;
2693 }
2694 else if (anArgCase == "-local")
2695 {
2696 toEraseLocal = Standard_True;
2697 }
a272ed94 2698 else if (anArgCase == "-view"
2699 || anArgCase == "-inview")
2700 {
2701 toEraseInView = Standard_True;
2702 }
b6d587e3 2703 else
2704 {
2705 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2706 }
2707 }
2708
b6d587e3 2709 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2710 {
b6d587e3 2711 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2712 return 1;
2713 }
7fd59977 2714
b6d587e3 2715 if (toEraseLocal && !aCtx->HasOpenedContext())
2716 {
2717 std::cerr << "Error: local selection context is not open.\n";
2718 return 1;
2719 }
2720 else if (!toEraseLocal && aCtx->HasOpenedContext())
2721 {
2722 aCtx->CloseAllContexts (Standard_False);
2723 }
2724
2725 if (!aNamesOfEraseIO.IsEmpty())
2726 {
2727 // Erase named objects
2728 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2729 {
b6d587e3 2730 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2731 if (!GetMapOfAIS().IsBound2 (aName))
2732 {
2733 continue;
2734 }
7fd59977 2735
b514beda 2736 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2737 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2738 theDI << aName.ToCString() << " ";
2739 if (!anIO.IsNull())
2740 {
a272ed94 2741 if (toEraseInView)
2742 {
2743 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2744 }
2745 else
2746 {
2747 aCtx->Erase (anIO, Standard_False);
2748 }
b514beda 2749 }
7fd59977 2750 }
7fd59977 2751 }
c3282ec1 2752 else if (!toEraseAll && aCtx->NbSelected() > 0)
b514beda 2753 {
b6d587e3 2754 // Erase selected objects
b514beda 2755 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2756 anIter.More(); anIter.Next())
2757 {
2758 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2759 if (!anIO.IsNull()
c3282ec1 2760 && aCtx->IsSelected (anIO))
b514beda 2761 {
2762 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2763 if (toEraseInView)
2764 {
2765 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2766 }
2767 else
2768 {
2769 aCtx->Erase (anIO, Standard_False);
2770 }
7fd59977 2771 }
2772 }
b514beda 2773 }
519d35d8 2774 else
b514beda 2775 {
b6d587e3 2776 // Erase all objects
519d35d8 2777 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2778 anIter.More(); anIter.Next())
b514beda 2779 {
519d35d8 2780 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2781 if (!anIO.IsNull())
2782 {
a272ed94 2783 if (toEraseInView)
2784 {
2785 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2786 }
2787 else
2788 {
2789 aCtx->Erase (anIO, Standard_False);
2790 }
519d35d8 2791 }
7fd59977 2792 }
7fd59977 2793 }
b6d587e3 2794
7fd59977 2795 return 0;
2796}
2797
7fd59977 2798//==============================================================================
2799//function : VDisplayAll
2800//author : ege
2801//purpose : Display all the objects of the Map
7fd59977 2802//==============================================================================
519d35d8 2803static int VDisplayAll (Draw_Interpretor& ,
2804 Standard_Integer theArgNb,
2805 const char** theArgVec)
7fd59977 2806
2807{
4e18052b 2808 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2809 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2810 if (aCtx.IsNull())
519d35d8 2811 {
b6d587e3 2812 std::cerr << "Error: no active view!\n";
519d35d8 2813 return 1;
2814 }
2815
519d35d8 2816 Standard_Integer anArgIter = 1;
b6d587e3 2817 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2818 for (; anArgIter < theArgNb; ++anArgIter)
2819 {
b6d587e3 2820 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2821 anArgCase.LowerCase();
2822 if (anArgCase == "-local")
2823 {
2824 toDisplayLocal = Standard_True;
2825 }
2826 else if (anUpdateTool.parseRedrawMode (anArgCase))
2827 {
2828 continue;
2829 }
2830 else
519d35d8 2831 {
2832 break;
7fd59977 2833 }
519d35d8 2834 }
2835 if (anArgIter < theArgNb)
2836 {
2837 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2838 return 1;
2839 }
2840
b6d587e3 2841 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2842 {
b6d587e3 2843 std::cerr << "Error: local selection context is not open.\n";
2844 return 1;
2845 }
2846 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2847 {
2848 aCtx->CloseLocalContext (Standard_False);
519d35d8 2849 }
2850
2851 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2852 anIter.More(); anIter.Next())
2853 {
d09dda09 2854 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2855 aCtx->Erase (aShape, Standard_False);
519d35d8 2856 }
2857
2858 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2859 anIter.More(); anIter.Next())
2860 {
d09dda09 2861 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2862 aCtx->Display (aShape, Standard_False);
7fd59977 2863 }
2864 return 0;
2865}
2866
c2a388f8 2867//! Auxiliary method to find presentation
2868inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2869 const Handle(AIS_InteractiveObject)& theIO,
2870 const Standard_Integer theMode)
2871{
2872 if (theIO.IsNull())
2873 {
2874 return Handle(PrsMgr_Presentation)();
2875 }
2876
2877 if (theMode != -1)
2878 {
2879 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2880 {
2881 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2882 }
2883 }
2884 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2885 {
2886 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2887 }
2888 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2889 {
2890 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2891 }
2892 return Handle(PrsMgr_Presentation)();
2893}
2894
2895enum ViewerTest_BndAction
2896{
2897 BndAction_Hide,
2898 BndAction_Show,
2899 BndAction_Print
2900};
2901
2902//! Auxiliary method to print bounding box of presentation
2903inline void bndPresentation (Draw_Interpretor& theDI,
2904 const Handle(PrsMgr_Presentation)& thePrs,
2905 const TCollection_AsciiString& theName,
2906 const ViewerTest_BndAction theAction)
2907{
2908 switch (theAction)
2909 {
2910 case BndAction_Hide:
2911 {
2912 thePrs->Presentation()->GraphicUnHighlight();
2913 break;
2914 }
2915 case BndAction_Show:
2916 {
5b111128 2917 Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
a1954302 2918 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2919 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2920 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2921 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
c2a388f8 2922 break;
2923 }
2924 case BndAction_Print:
2925 {
ed063270 2926 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2927 gp_Pnt aMin = aBox.CornerMin();
2928 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 2929 theDI << theName << "\n"
ed063270 2930 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2931 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 2932 break;
2933 }
2934 }
2935}
2936
2937//==============================================================================
2938//function : VBounding
2939//purpose :
2940//==============================================================================
2941int VBounding (Draw_Interpretor& theDI,
2942 Standard_Integer theArgNb,
2943 const char** theArgVec)
2944{
2945 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2946 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2947 if (aCtx.IsNull())
2948 {
2949 std::cout << "Error: no active view!\n";
2950 return 1;
2951 }
2952
4e18052b 2953 ViewerTest_BndAction anAction = BndAction_Show;
2954 Standard_Integer aMode = -1;
c2a388f8 2955
2956 Standard_Integer anArgIter = 1;
2957 for (; anArgIter < theArgNb; ++anArgIter)
2958 {
2959 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2960 anArg.LowerCase();
2961 if (anArg == "-print")
2962 {
2963 anAction = BndAction_Print;
2964 }
2965 else if (anArg == "-show")
2966 {
2967 anAction = BndAction_Show;
2968 }
2969 else if (anArg == "-hide")
2970 {
2971 anAction = BndAction_Hide;
2972 }
2973 else if (anArg == "-mode")
2974 {
2975 if (++anArgIter >= theArgNb)
2976 {
2977 std::cout << "Error: wrong syntax at " << anArg << "\n";
2978 return 1;
2979 }
2980 aMode = Draw::Atoi (theArgVec[anArgIter]);
2981 }
4e18052b 2982 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 2983 {
2984 break;
2985 }
2986 }
2987
2988 if (anArgIter < theArgNb)
2989 {
2990 // has a list of names
2991 for (; anArgIter < theArgNb; ++anArgIter)
2992 {
2993 TCollection_AsciiString aName = theArgVec[anArgIter];
2994 if (!GetMapOfAIS().IsBound2 (aName))
2995 {
2996 std::cout << "Error: presentation " << aName << " does not exist\n";
2997 return 1;
2998 }
2999
3000 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3001 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3002 if (aPrs.IsNull())
3003 {
3004 std::cout << "Error: presentation " << aName << " does not exist\n";
3005 return 1;
3006 }
3007 bndPresentation (theDI, aPrs, aName, anAction);
3008 }
3009 }
c3282ec1 3010 else if (aCtx->NbSelected() > 0)
c2a388f8 3011 {
3012 // remove all currently selected objects
c3282ec1 3013 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
c2a388f8 3014 {
c3282ec1 3015 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
c2a388f8 3016 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3017 if (!aPrs.IsNull())
3018 {
3019 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
3020 }
3021 }
3022 }
3023 else
3024 {
3025 // all objects
3026 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3027 anIter.More(); anIter.Next())
3028 {
3029 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3030 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3031 if (!aPrs.IsNull())
3032 {
3033 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
3034 }
3035 }
3036 }
c2a388f8 3037 return 0;
3038}
3039
d399d3c3 3040//==============================================================================
3041//function : VTexture
3042//purpose :
3043//==============================================================================
3044Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 3045{
d399d3c3 3046 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 3047
900f7229 3048 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 3049 if (aCommandName == "vtexture")
3050 {
3051 if (theArgsNb < 2)
7fd59977 3052 {
d399d3c3 3053 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
3054 std::cout << "Type help for more information.\n";
31160f80 3055 return 1;
7fd59977 3056 }
3057
d399d3c3 3058 // look for options of vtexture command
3059 TCollection_AsciiString aParseKey;
3060 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3061 {
3062 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 3063
d399d3c3 3064 anArg.UpperCase();
3065 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3066 {
3067 aParseKey = anArg;
3068 aParseKey.Remove (1);
3069 aParseKey.UpperCase();
900f7229 3070 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 3071 continue;
3072 }
3073
3074 if (aParseKey.IsEmpty())
3075 {
3076 continue;
3077 }
3078
900f7229 3079 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 3080 }
3081 }
3082 else if (aCommandName == "vtexscale"
3083 || aCommandName == "vtexorigin"
3084 || aCommandName == "vtexrepeat")
3085 {
3086 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3087 // equal to -scale, -origin, -repeat options of vtexture command
3088 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 3089 {
d399d3c3 3090 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
3091 std::cout << "Type help for more information.\n";
31160f80 3092 return 1;
7fd59977 3093 }
3094
900f7229 3095 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 3096 if (theArgsNb == 2)
3097 {
900f7229 3098 anArgs->Append ("OFF");
d399d3c3 3099 }
3100 else if (theArgsNb == 4)
3101 {
900f7229 3102 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3103 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 3104 }
7fd59977 3105
d399d3c3 3106 TCollection_AsciiString anArgKey;
3107 if (aCommandName == "vtexscale")
3108 {
3109 anArgKey = "SCALE";
3110 }
3111 else if (aCommandName == "vtexorigin")
3112 {
3113 anArgKey = "ORIGIN";
3114 }
3115 else
3116 {
3117 anArgKey = "REPEAT";
3118 }
3119
3120 aMapOfArgs.Bind (anArgKey, anArgs);
3121 }
3122 else if (aCommandName == "vtexdefault")
7fd59977 3123 {
d399d3c3 3124 // scan for parameters of vtexdefault command
3125 // equal to -default option of vtexture command
900f7229 3126 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 3127 }
3128
d399d3c3 3129 // Check arguments for validity
900f7229 3130 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 3131 for (; aMapIt.More(); aMapIt.Next())
3132 {
3133 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 3134 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 3135
3136 // -scale, -origin, -repeat: one argument "off", or two real values
3137 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 3138 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3139 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 3140 {
d399d3c3 3141 continue;
7fd59977 3142 }
d399d3c3 3143
3144 // -modulate: single argument "on" / "off"
900f7229 3145 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 3146 {
3147 continue;
3148 }
3149
3150 // -default: no arguments
900f7229 3151 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 3152 {
3153 continue;
3154 }
3155
3156 TCollection_AsciiString aLowerKey;
3157 aLowerKey = "-";
3158 aLowerKey += aKey;
3159 aLowerKey.LowerCase();
3160 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3161 std::cout << "Type help for more information.\n";
3162 return 1;
3163 }
3164
3165 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3166 if (anAISContext.IsNull())
3167 {
3168 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
3169 return 1;
3170 }
3171
3172 Standard_Integer aPreviousMode = 0;
3173
3174 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
3175
3176 TCollection_AsciiString aShapeName (theArgv[1]);
3177 Handle(AIS_InteractiveObject) anIO;
3178
3179 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3180 if (aMapOfIO.IsBound2 (aShapeName))
3181 {
3182 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3183 }
3184
3185 if (anIO.IsNull())
3186 {
3187 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3188 return 1;
3189 }
3190
3191 Handle(AIS_TexturedShape) aTexturedIO;
3192 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3193 {
3194 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3195 aPreviousMode = aTexturedIO->DisplayMode();
3196 }
7fd59977 3197 else
d399d3c3 3198 {
2195ab96 3199 anAISContext->Remove (anIO, Standard_False);
d399d3c3 3200 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3201 GetMapOfAIS().UnBind1 (anIO);
3202 GetMapOfAIS().UnBind2 (aShapeName);
3203 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3204 }
3205
3206 // -------------------------------------------
3207 // Turn texturing on/off - only for vtexture
3208 // -------------------------------------------
3209
3210 if (aCommandName == "vtexture")
3211 {
3212 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3213
3214 if (aTextureArg.IsEmpty())
7fd59977 3215 {
d399d3c3 3216 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3217 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3218
3219 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3220 if (aPreviousMode == 3)
3221 {
3222 anAISContext->RecomputePrsOnly (aTexturedIO);
3223 }
3224
3225 anAISContext->Display (aTexturedIO, Standard_True);
3226 return 0;
7fd59977 3227 }
d399d3c3 3228 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3229 {
d399d3c3 3230 if (aTextureArg == "?")
3231 {
3232 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3233
d399d3c3 3234 theDi << "\n Files in current directory : \n" << "\n";
3235 theDi.Eval ("glob -nocomplain *");
7fd59977 3236
d399d3c3 3237 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3238 aCmnd += aTextureFolder;
3239 aCmnd += "/* ";
7fd59977 3240
d399d3c3 3241 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3242 theDi.Eval (aCmnd.ToCString());
3243 return 0;
3244 }
3245 else
3246 {
3247 aTexturedIO->SetTextureFileName (aTextureArg);
3248 }
3249 }
3250 }
7fd59977 3251
d399d3c3 3252 // ------------------------------------
3253 // Process other options and commands
3254 // ------------------------------------
7fd59977 3255
900f7229 3256 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3257 if (aMapOfArgs.Find ("DEFAULT", aValues))
3258 {
3259 aTexturedIO->SetTextureRepeat (Standard_False);
3260 aTexturedIO->SetTextureOrigin (Standard_False);
3261 aTexturedIO->SetTextureScale (Standard_False);
3262 aTexturedIO->EnableTextureModulate();
3263 }
3264 else
3265 {
3266 if (aMapOfArgs.Find ("SCALE", aValues))
3267 {
900f7229 3268 if (aValues->Value(1) != "OFF")
d399d3c3 3269 {
900f7229 3270 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3271 }
7fd59977 3272 else
d399d3c3 3273 {
3274 aTexturedIO->SetTextureScale (Standard_False);
3275 }
3276 }
7fd59977 3277
d399d3c3 3278 if (aMapOfArgs.Find ("ORIGIN", aValues))
3279 {
900f7229 3280 if (aValues->Value(1) != "OFF")
d399d3c3 3281 {
900f7229 3282 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3283 }
3284 else
3285 {
3286 aTexturedIO->SetTextureOrigin (Standard_False);
3287 }
3288 }
7fd59977 3289
d399d3c3 3290 if (aMapOfArgs.Find ("REPEAT", aValues))
3291 {
900f7229 3292 if (aValues->Value(1) != "OFF")
d399d3c3 3293 {
900f7229 3294 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3295 }
3296 else
3297 {
3298 aTexturedIO->SetTextureRepeat (Standard_False);
3299 }
7fd59977 3300 }
3301
d399d3c3 3302 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 3303 {
900f7229 3304 if (aValues->Value(1) == "ON")
d399d3c3 3305 {
3306 aTexturedIO->EnableTextureModulate();
3307 }
3308 else
3309 {
3310 aTexturedIO->DisableTextureModulate();
3311 }
7fd59977 3312 }
d399d3c3 3313 }
3314
3315 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3316 {
3317 anAISContext->RecomputePrsOnly (aTexturedIO);
3318 }
3319 else
3320 {
3321 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3322 anAISContext->Display (aTexturedIO, Standard_True);
3323 anAISContext->Update (aTexturedIO,Standard_True);
3324 }
3325
31160f80 3326 return 0;
7fd59977 3327}
3328
af65fb19 3329//! Auxiliary method to parse transformation persistence flags
3330inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3331 Standard_Integer& theFlags)
3332{
3333 if (theFlagString == "pan")
3334 {
3335 theFlags |= Graphic3d_TMF_PanPers;
3336 }
3337 else if (theFlagString == "zoom")
3338 {
3339 theFlags |= Graphic3d_TMF_ZoomPers;
3340 }
3341 else if (theFlagString == "rotate")
3342 {
3343 theFlags |= Graphic3d_TMF_RotatePers;
3344 }
3345 else if (theFlagString == "trihedron")
3346 {
3347 theFlags = Graphic3d_TMF_TriedronPers;
3348 }
3349 else if (theFlagString == "full")
3350 {
3351 theFlags = Graphic3d_TMF_FullPers;
3352 }
3353 else if (theFlagString == "none")
3354 {
3355 theFlags = Graphic3d_TMF_None;
3356 }
3357 else
3358 {
3359 return Standard_False;
3360 }
3361
3362 return Standard_True;
3363}
3364
7fd59977 3365//==============================================================================
3366//function : VDisplay2
3367//author : ege
3368//purpose : Display an object from its name
7fd59977 3369//==============================================================================
519d35d8 3370static int VDisplay2 (Draw_Interpretor& theDI,
3371 Standard_Integer theArgNb,
3372 const char** theArgVec)
7fd59977 3373{
519d35d8 3374 if (theArgNb < 2)
3375 {
b6d587e3 3376 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 3377 return 1;
3378 }
b6d587e3 3379
3380 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3381 if (aCtx.IsNull())
519d35d8 3382 {
7fd59977 3383 ViewerTest::ViewerInit();
4e18052b 3384 aCtx = ViewerTest::GetAISContext();
7fd59977 3385 }
3386
b6d587e3 3387 // Parse input arguments
4e18052b 3388 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 3389 Standard_Integer isMutable = -1;
3390 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3391 Standard_Boolean toDisplayLocal = Standard_False;
3392 Standard_Boolean toReDisplay = Standard_False;
af65fb19 3393 Standard_Integer isSelectable = -1;
3394 Standard_Integer anObjDispMode = -2;
3395 Standard_Integer anObjHighMode = -2;
3396 Standard_Boolean toSetTrsfPers = Standard_False;
3397 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3398 gp_Pnt aTPPosition;
b6d587e3 3399 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 3400 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94 3401 Standard_Integer toDisplayInView = Standard_False;
519d35d8 3402 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3403 {
b7cd4ba7 3404 const TCollection_AsciiString aName = theArgVec[anArgIter];
3405 TCollection_AsciiString aNameCase = aName;
3406 aNameCase.LowerCase();
4e18052b 3407 if (anUpdateTool.parseRedrawMode (aName))
519d35d8 3408 {
3409 continue;
3410 }
b7cd4ba7 3411 else if (aNameCase == "-mutable")
3412 {
3413 isMutable = 1;
b7cd4ba7 3414 }
a1954302 3415 else if (aNameCase == "-neutral")
3416 {
3417 aDispStatus = AIS_DS_Displayed;
3418 }
3419 else if (aNameCase == "-immediate"
3420 || aNameCase == "-top")
3421 {
3422 aZLayer = Graphic3d_ZLayerId_Top;
3423 }
3424 else if (aNameCase == "-topmost")
3425 {
3426 aZLayer = Graphic3d_ZLayerId_Topmost;
3427 }
3428 else if (aNameCase == "-osd"
af65fb19 3429 || aNameCase == "-toposd"
3430 || aNameCase == "-overlay")
a1954302 3431 {
3432 aZLayer = Graphic3d_ZLayerId_TopOSD;
3433 }
af65fb19 3434 else if (aNameCase == "-botosd"
3435 || aNameCase == "-underlay")
3436 {
3437 aZLayer = Graphic3d_ZLayerId_BotOSD;
3438 }
3439 else if (aNameCase == "-select"
3440 || aNameCase == "-selectable")
3441 {
3442 isSelectable = 1;
3443 }
3444 else if (aNameCase == "-noselect"
3445 || aNameCase == "-noselection")
3446 {