0026641: Visualization, TKOpenGl - handle correctly transformation persistence within...
[occt.git] / src / ViewerTest / ViewerTest.cxx
CommitLineData
b311480e 1// Created on: 1997-07-23
2// Created by: Henri JEANNIN
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
7fd59977 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
17// Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
7fd59977 18// Modified by Robert Coublanc [nov 16-17-18 1998]
19// -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20// ViewerTest_ObjectCommands.cxx
21// ViewerTest_RelationCommands.cxx
22// -add Functions and commands for interactive selection of shapes and objects
23// in AIS Viewers. (PickShape(s), PickObject(s),
24
25#include <Standard_Stream.hxx>
26
27#include <ViewerTest.hxx>
189f85a3 28#include <ViewerTest_CmdParser.hxx>
4e18052b 29
7fd59977 30#include <TopLoc_Location.hxx>
31#include <TopTools_HArray1OfShape.hxx>
32#include <TColStd_HArray1OfTransient.hxx>
b6d587e3 33#include <TColStd_SequenceOfAsciiString.hxx>
900f7229 34#include <TColStd_HSequenceOfAsciiString.hxx>
b6d587e3 35#include <TColStd_MapOfTransient.hxx>
7fd59977 36#include <OSD_Timer.hxx>
37#include <Geom_Axis2Placement.hxx>
38#include <Geom_Axis1Placement.hxx>
39#include <gp_Trsf.hxx>
40#include <TopExp_Explorer.hxx>
41#include <BRepAdaptor_Curve.hxx>
42#include <StdSelect_ShapeTypeFilter.hxx>
43#include <AIS.hxx>
ad3217cd 44#include <AIS_ColoredShape.hxx>
7fd59977 45#include <AIS_InteractiveObject.hxx>
46#include <AIS_Trihedron.hxx>
47#include <AIS_Axis.hxx>
48#include <AIS_Relation.hxx>
49#include <AIS_TypeFilter.hxx>
50#include <AIS_SignatureFilter.hxx>
cb78155f 51#include <AIS_LocalContext.hxx>
7fd59977 52#include <AIS_ListOfInteractive.hxx>
53#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 54#include <Aspect_InteriorStyle.hxx>
34db9c00 55#include <Aspect_Window.hxx>
99c56d44 56#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 57#include <Graphic3d_AspectLine3d.hxx>
a1954302 58#include <Graphic3d_CStructure.hxx>
392ac980 59#include <Graphic3d_TextureRoot.hxx>
692613e5 60#include <Image_AlienPixMap.hxx>
6262338c 61#include <Prs3d_Drawer.hxx>
99c56d44 62#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 63#include <Prs3d_IsoAspect.hxx>
6262338c 64#include <Prs3d_PointAspect.hxx>
8e7c8ccf 65#include <Select3D_SensitiveWire.hxx>
8b9a309b 66#include <Select3D_SensitivePrimitiveArray.hxx>
8e7c8ccf 67#include <SelectMgr_EntityOwner.hxx>
68#include <StdSelect_BRepOwner.hxx>
69#include <StdSelect_ViewerSelector3d.hxx>
cb78155f 70#include <TopTools_MapOfShape.hxx>
4e18052b 71#include <ViewerTest_AutoUpdater.hxx>
7fd59977 72
7fd59977 73#include <stdio.h>
7fd59977 74
75#include <Draw_Interpretor.hxx>
76#include <TCollection_AsciiString.hxx>
77#include <Draw_PluginMacro.hxx>
7fd59977 78
79// avoid warnings on 'extern "C"' functions returning C++ classes
57c28b61 80#ifdef _MSC_VER
7fd59977 81#define _CRT_SECURE_NO_DEPRECATE
82#pragma warning(4:4190)
83#pragma warning (disable:4996)
84#endif
85
7fd59977 86extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
87
7fd59977 88#include <Quantity_Color.hxx>
89#include <Quantity_NameOfColor.hxx>
90
91#include <Graphic3d_NameOfMaterial.hxx>
92
6262338c 93#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
94#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
95#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
7fd59977 96
792c785c 97//=======================================================================
98//function : GetColorFromName
99//purpose : get the Quantity_NameOfColor from a string
100//=======================================================================
7fd59977 101
792c785c 102Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
103{
8316c618 104 Quantity_NameOfColor aColor = DEFAULT_COLOR;
105 Quantity_Color::ColorFromName (theName, aColor);
106 return aColor;
7fd59977 107}
108
536d98e2 109//=======================================================================
110//function : ParseColor
111//purpose :
112//=======================================================================
113
114Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
115 const char** theArgVec,
116 Quantity_Color& theColor)
117{
118 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
119 if (theArgNb >= 1
120 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
121 {
122 theColor = aColor;
123 return 1;
124 }
125 else if (theArgNb >= 3)
126 {
127 const TCollection_AsciiString anRgbStr[3] =
128 {
129 theArgVec[0],
130 theArgVec[1],
131 theArgVec[2]
132 };
133 if (!anRgbStr[0].IsRealValue()
134 || !anRgbStr[1].IsRealValue()
135 || !anRgbStr[2].IsRealValue())
136 {
137 return 0;
138 }
139
140 Graphic3d_Vec4d anRgb;
141 anRgb.x() = anRgbStr[0].RealValue();
142 anRgb.y() = anRgbStr[1].RealValue();
143 anRgb.z() = anRgbStr[2].RealValue();
144 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
145 || anRgb.y() < 0.0 || anRgb.y() > 1.0
146 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
147 {
148 std::cout << "Error: RGB color values should be within range 0..1!\n";
149 return 0;
150 }
151
152 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
153 return 3;
154 }
155
156 return 0;
157}
158
a5565a3c 159//=======================================================================
160//function : ParseOnOff
161//purpose :
162//=======================================================================
163Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
164 Standard_Boolean& theIsOn)
165{
166 TCollection_AsciiString aFlag(theArg);
167 aFlag.LowerCase();
168 if (aFlag == "on"
169 || aFlag == "1")
170 {
171 theIsOn = Standard_True;
172 return Standard_True;
173 }
174 else if (aFlag == "off"
175 || aFlag == "0")
176 {
177 theIsOn = Standard_False;
178 return Standard_True;
179 }
180 return Standard_False;
181}
182
7fd59977 183//=======================================================================
184//function : GetTypeNames
185//purpose :
186//=======================================================================
187static const char** GetTypeNames()
188{
189 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
190 "Shape","ConnectedShape","MultiConn.Shape",
191 "ConnectedInter.","MultiConn.",
192 "Constraint","Dimension"};
193 static const char** ThePointer = names;
194 return ThePointer;
195}
196
197//=======================================================================
198//function : GetTypeAndSignfromString
199//purpose :
200//=======================================================================
201void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
202{
203 const char ** thefullnames = GetTypeNames();
204 Standard_Integer index(-1);
205
206 for(Standard_Integer i=0;i<=13 && index==-1;i++)
207 if(!strcasecmp(name,thefullnames[i]))
208 index = i;
209
210 if(index ==-1){
211 TheType = AIS_KOI_None;
212 TheSign = -1;
213 return;
214 }
215
216 if(index<=6){
217 TheType = AIS_KOI_Datum;
218 TheSign = index+1;
219 }
220 else if (index <=9){
221 TheType = AIS_KOI_Shape;
222 TheSign = index-7;
223 }
224 else if(index<=11){
225 TheType = AIS_KOI_Object;
226 TheSign = index-10;
227 }
228 else{
229 TheType = AIS_KOI_Relation;
230 TheSign = index-12;
231 }
232
233}
234
235
236
237#include <string.h>
238#include <Draw_Interpretor.hxx>
239#include <Draw.hxx>
240#include <Draw_Appli.hxx>
241#include <DBRep.hxx>
242
243
244#include <TCollection_AsciiString.hxx>
245#include <V3d_Viewer.hxx>
246#include <V3d_View.hxx>
247#include <V3d.hxx>
248
249#include <AIS_InteractiveContext.hxx>
250#include <AIS_Shape.hxx>
251#include <AIS_TexturedShape.hxx>
252#include <AIS_DisplayMode.hxx>
253#include <TColStd_MapOfInteger.hxx>
254#include <AIS_MapOfInteractive.hxx>
255#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
256#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
257#include <ViewerTest_EventManager.hxx>
258
259#include <TopoDS_Solid.hxx>
260#include <BRepTools.hxx>
261#include <BRep_Builder.hxx>
262#include <TopAbs_ShapeEnum.hxx>
263
264#include <TopoDS.hxx>
265#include <BRep_Tool.hxx>
266
267
268#include <Draw_Window.hxx>
269#include <AIS_ListIteratorOfListOfInteractive.hxx>
270#include <AIS_ListOfInteractive.hxx>
271#include <AIS_DisplayMode.hxx>
272#include <TopTools_ListOfShape.hxx>
273#include <BRepOffsetAPI_MakeThickSolid.hxx>
274#include <BRepOffset.hxx>
275
7fd59977 276//==============================================================================
277// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
278//==============================================================================
279Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
280 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
281 return TheMap;
282}
283
29e2c6d2 284//=======================================================================
285//function : Display
286//purpose :
287//=======================================================================
288Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
289 const Handle(AIS_InteractiveObject)& theObject,
290 const Standard_Boolean theToUpdate,
291 const Standard_Boolean theReplaceIfExists)
9558a876
A
292{
293 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29e2c6d2 294 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
295 if (aCtx.IsNull())
9558a876 296 {
29e2c6d2 297 std::cout << "Error: AIS context is not available.\n";
9558a876
A
298 return Standard_False;
299 }
300
301 if (aMap.IsBound2 (theName))
302 {
303 if (!theReplaceIfExists)
304 {
29e2c6d2 305 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
9558a876
A
306 << "Please use another name.\n";
307 return Standard_False;
308 }
309
29e2c6d2 310 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
9558a876 311 if (!anOldObj.IsNull())
29e2c6d2 312 {
313 aCtx->Remove (anOldObj, Standard_True);
314 }
9558a876
A
315 aMap.UnBind2 (theName);
316 }
317
29e2c6d2 318 if (theObject.IsNull())
208e6839 319 {
29e2c6d2 320 // object with specified name has been already unbound
208e6839 321 return Standard_True;
322 }
323
29e2c6d2 324 // unbind AIS object if it was bound with another name
325 aMap.UnBind1 (theObject);
9558a876
A
326
327 // can be registered without rebinding
29e2c6d2 328 aMap.Bind (theObject, theName);
329 aCtx->Display (theObject, theToUpdate);
9558a876
A
330 return Standard_True;
331}
332
29e2c6d2 333//! Alias for ViewerTest::Display(), compatibility with old code.
334Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
335 const Handle(AIS_InteractiveObject)& theObject,
336 Standard_Boolean theReplaceIfExists = Standard_True)
337{
338 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
339}
340
7fd59977 341static TColStd_MapOfInteger theactivatedmodes(8);
342static TColStd_ListOfTransient theEventMgrs;
343
d09dda09 344static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
7fd59977 345 const Handle(AIS_InteractiveContext)& Ctx)
346{
347 theEventMgrs.Clear();
348 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
349}
350
24de79c3 351static Handle(V3d_View)& a3DView()
352{
7fd59977 353 static Handle(V3d_View) Viou;
354 return Viou;
355}
356
24de79c3 357
7fd59977 358Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
359 static Handle(AIS_InteractiveContext) aContext;
360 return aContext;
361}
362
24de79c3 363const Handle(V3d_View)& ViewerTest::CurrentView()
7fd59977 364{
365 return a3DView();
366}
367void ViewerTest::CurrentView(const Handle(V3d_View)& V)
368{
369 a3DView() = V;
370}
371
24de79c3 372const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
7fd59977 373{
374 return TheAISContext();
375}
376
377void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
378{
379 TheAISContext() = aCtx;
380 ViewerTest::ResetEventManager();
381}
382
383Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
384{
4952a30a 385 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 386}
387
388Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
389{
4952a30a 390 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 391}
392
393
394void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
395 theEventMgrs.Prepend(EM);
396}
397
398void ViewerTest::UnsetEventManager()
399{
400 theEventMgrs.RemoveFirst();
401}
402
403
404void ViewerTest::ResetEventManager()
405{
d09dda09 406 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 407 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
408}
409
410Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
411{
412 Handle(ViewerTest_EventManager) EM;
413 if(theEventMgrs.IsEmpty()) return EM;
414 Handle(Standard_Transient) Tr = theEventMgrs.First();
c5f3a425 415 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
7fd59977 416 return EM;
417}
418
7fd59977 419//=======================================================================
34db9c00 420//function : Get Context and active view
7fd59977 421//purpose :
422//=======================================================================
34db9c00 423static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
424 Handle(V3d_View)& theView)
7fd59977 425{
34db9c00 426 theCtx = ViewerTest::GetAISContext();
427 theView = ViewerTest::CurrentView();
428 if (theCtx.IsNull()
429 || theView.IsNull())
7fd59977 430 {
34db9c00 431 std::cout << "Error: cannot find an active view!\n";
432 return Standard_False;
7fd59977 433 }
34db9c00 434 return Standard_True;
7fd59977 435}
436
7fd59977 437//==============================================================================
438//function : GetShapeFromName
439//purpose : Compute an Shape from a draw variable or a file name
440//==============================================================================
441
442static TopoDS_Shape GetShapeFromName(const char* name)
443{
444 TopoDS_Shape S = DBRep::Get(name);
445
446 if ( S.IsNull() ) {
447 BRep_Builder aBuilder;
448 BRepTools::Read( S, name, aBuilder);
449 }
450
451 return S;
452}
4e18e72a 453
7fd59977 454//==============================================================================
455//function : GetAISShapeFromName
456//purpose : Compute an AIS_Shape from a draw variable or a file name
457//==============================================================================
458Handle(AIS_Shape) GetAISShapeFromName(const char* name)
459{
460 Handle(AIS_Shape) retsh;
461
462 if(GetMapOfAIS().IsBound2(name)){
463 const Handle(AIS_InteractiveObject) IO =
464 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
465 if (!IO.IsNull()) {
eafb234b 466 if(IO->Type()==AIS_KOI_Shape) {
7fd59977 467 if(IO->Signature()==0){
c5f3a425 468 retsh = Handle(AIS_Shape)::DownCast (IO);
7fd59977 469 }
470 else
471 cout << "an Object which is not an AIS_Shape "
472 "already has this name!!!"<<endl;
eafb234b 473 }
7fd59977 474 }
475 return retsh;
476 }
477
478
479 TopoDS_Shape S = GetShapeFromName(name);
480 if ( !S.IsNull() ) {
481 retsh = new AIS_Shape(S);
482 }
483 return retsh;
484}
485
486
487//==============================================================================
488//function : Clear
489//purpose : Remove all the object from the viewer
490//==============================================================================
491void ViewerTest::Clear()
492{
493 if ( !a3DView().IsNull() ) {
494 if (TheAISContext()->HasOpenedContext())
495 TheAISContext()->CloseLocalContext();
496 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
497 while ( it.More() ) {
498 cout << "Remove " << it.Key2() << endl;
d09dda09 499 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
500 TheAISContext()->Remove(anObj,Standard_False);
7fd59977 501 it.Next();
502 }
f751596e 503 TheAISContext()->RebuildSelectionStructs();
7fd59977 504 TheAISContext()->UpdateCurrentViewer();
7fd59977 505 GetMapOfAIS().Clear();
506 }
507}
508
509//==============================================================================
510//function : StandardModesActivation
511//purpose : Activate a selection mode, vertex, edge, wire ..., in a local
512// Context
513//==============================================================================
514void ViewerTest::StandardModeActivation(const Standard_Integer mode )
515{
516 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
517 if(mode==0) {
518 if (TheAISContext()->HasOpenedContext())
519 aContext->CloseLocalContext();
520 } else {
521
522 if(!aContext->HasOpenedContext()) {
523 // To unhilight the preselected object
c3282ec1 524 aContext->UnhilightSelected(Standard_False);
7fd59977 525 // Open a local Context in order to be able to select subshape from
526 // the selected shape if any or for all if there is no selection
c3282ec1 527 if (!aContext->FirstSelectedObject().IsNull()){
7fd59977 528 aContext->OpenLocalContext(Standard_False);
529
c3282ec1 530 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
531 aContext->Load( aContext->SelectedInteractive(),-1,Standard_True);
7fd59977 532 }
533 }
534 else
535 aContext->OpenLocalContext();
536 }
537
538 const char *cmode="???";
539
540 switch (mode) {
541 case 0: cmode = "Shape"; break;
542 case 1: cmode = "Vertex"; break;
543 case 2: cmode = "Edge"; break;
544 case 3: cmode = "Wire"; break;
545 case 4: cmode = "Face"; break;
546 case 5: cmode = "Shell"; break;
547 case 6: cmode = "Solid"; break;
4754e164 548 case 7: cmode = "Compsolid"; break;
549 case 8: cmode = "Compound"; break;
7fd59977 550 }
551
552 if(theactivatedmodes.Contains(mode))
553 { // Desactivate
554 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
555 theactivatedmodes.Remove(mode);
556 cout<<"Mode "<< cmode <<" OFF"<<endl;
557 }
558 else
559 { // Activate
560 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
561 theactivatedmodes.Add(mode);
562 cout<<"Mode "<< cmode << " ON" << endl;
563 }
564 }
565}
566
1c88cbaf 567//==============================================================================
568//function : CopyIsoAspect
569//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
570//==============================================================================
571static Handle(Prs3d_IsoAspect) CopyIsoAspect
572 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
573 const Standard_Integer theNbIsos)
574{
575 Quantity_Color aColor;
576 Aspect_TypeOfLine aType;
577 Standard_Real aWidth;
578
579 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
580
581 Handle(Prs3d_IsoAspect) aResult =
582 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
583
584 return aResult;
585}
586
587//==============================================================================
588//function : visos
589//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
590//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
591//==============================================================================
592static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
593{
594 if (TheAISContext().IsNull()) {
595 di << argv[0] << " Call 'vinit' before!\n";
596 return 1;
597 }
598
599 if (argc <= 1) {
600 di << "Current number of isos : " <<
601 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
602 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
603 di << "IsoOnPlane mode is " <<
604 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
5ad8c033 605 di << "IsoOnTriangulation mode is " <<
606 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
1c88cbaf 607 return 0;
608 }
609
610 Standard_Integer aLastInd = argc - 1;
611 Standard_Boolean isChanged = Standard_False;
1d47d8d0 612 Standard_Integer aNbUIsos = 0;
613 Standard_Integer aNbVIsos = 0;
1c88cbaf 614
615 if (aLastInd >= 3) {
616 Standard_Boolean isIsoOnPlane = Standard_False;
617
618 if (strcmp(argv[aLastInd], "1") == 0) {
619 isIsoOnPlane = Standard_True;
620 isChanged = Standard_True;
621 } else if (strcmp(argv[aLastInd], "0") == 0) {
622 isIsoOnPlane = Standard_False;
623 isChanged = Standard_True;
624 }
625
626 if (isChanged) {
627 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
628 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
629 aLastInd -= 3;
630
631 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
632 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
633
634 TheAISContext()->IsoOnPlane(isIsoOnPlane);
635
636 if (aLastInd == 0) {
637 // If there are no shapes provided set the default numbers.
638 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
639 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
640 }
641 }
642 }
643
644 Standard_Integer i;
645
646 for (i = 1; i <= aLastInd; i++) {
647 TCollection_AsciiString name(argv[i]);
648 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
649
650 if (IsBound) {
651 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
652 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
653 const Handle(AIS_InteractiveObject) aShape =
654 Handle(AIS_InteractiveObject)::DownCast (anObj);
6262338c 655 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
1c88cbaf 656 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
657 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
658
659 if (isChanged) {
660 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
661 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
662 TheAISContext()->SetLocalAttributes
663 (aShape, CurDrawer, Standard_False);
664 TheAISContext()->Redisplay(aShape);
665 } else {
666 di << "Number of isos for " << argv[i] << " : "
667 << aUIso->Number() << " " << aVIso->Number() << "\n";
668 }
669 } else {
670 di << argv[i] << ": Not an AIS interactive object!\n";
671 }
672 } else {
673 di << argv[i] << ": Use 'vdisplay' before\n";
674 }
675 }
676
677 if (isChanged) {
678 TheAISContext()->UpdateCurrentViewer();
679 }
680
681 return 0;
682}
683
34db9c00 684static Standard_Integer VDispSensi (Draw_Interpretor& ,
685 Standard_Integer theArgNb,
686 Standard_CString* )
7fd59977 687{
34db9c00 688 if (theArgNb > 1)
689 {
690 std::cout << "Error: wrong syntax!\n";
691 return 1;
692 }
693
694 Handle(AIS_InteractiveContext) aCtx;
695 Handle(V3d_View) aView;
696 if (!getCtxAndView (aCtx, aView))
697 {
698 return 1;
699 }
700
701 aCtx->DisplayActiveSensitive (aView);
7fd59977 702 return 0;
703
704}
34db9c00 705
706static Standard_Integer VClearSensi (Draw_Interpretor& ,
707 Standard_Integer theArgNb,
708 Standard_CString* )
7fd59977 709{
34db9c00 710 if (theArgNb > 1)
711 {
712 std::cout << "Error: wrong syntax!\n";
713 return 1;
714 }
715
716 Handle(AIS_InteractiveContext) aCtx;
717 Handle(V3d_View) aView;
718 if (!getCtxAndView (aCtx, aView))
719 {
720 return 1;
721 }
722 aCtx->ClearActiveSensitive (aView);
7fd59977 723 return 0;
724}
725
726//==============================================================================
519d35d8 727//function : VDir
7fd59977 728//purpose : To list the displayed object with their attributes
7fd59977 729//==============================================================================
519d35d8 730static int VDir (Draw_Interpretor& theDI,
731 Standard_Integer ,
732 const char** )
733{
734 if (!a3DView().IsNull())
735 {
736 return 0;
7fd59977 737 }
738
519d35d8 739 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
740 anIter.More(); anIter.Next())
741 {
742 theDI << "\t" << anIter.Key2().ToCString() << "\n";
743 }
7fd59977 744 return 0;
745}
746
3c982548 747//==============================================================================
748//function : VSelPrecision
f751596e 749//purpose : To set the selection tolerance value
750//Draw arg : Selection tolerance value (real value determining the width and
751// height of selecting frustum bases). Without arguments the function
752// just prints current tolerance.
3c982548 753//==============================================================================
754static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
755{
f751596e 756 if( argc > 2 )
3c982548 757 {
28ee613b 758 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
3c982548 759 return 1;
760 }
761
762 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
763 if( aContext.IsNull() )
764 return 1;
765
766 if( argc == 1 )
767 {
f751596e 768 Standard_Real aPixelTolerance = aContext->PixelTolerance();
f751596e 769 di << "Pixel tolerance : " << aPixelTolerance << "\n";
3c982548 770 }
f751596e 771 else if (argc == 2)
3c982548 772 {
28ee613b 773 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
774 anArg.LowerCase();
775 if (anArg == "-unset")
776 {
3bf9a45f 777 aContext->SetPixelTolerance (-1);
28ee613b 778 }
779 else
780 {
3bf9a45f 781 aContext->SetPixelTolerance (anArg.IntegerValue());
28ee613b 782 }
3c982548 783 }
f751596e 784
3c982548 785 return 0;
786}
787
f978241f 788//! Auxiliary enumeration
789enum ViewerTest_StereoPair
790{
791 ViewerTest_SP_Single,
792 ViewerTest_SP_SideBySide,
793 ViewerTest_SP_OverUnder
794};
795
7fd59977 796//==============================================================================
797//function : VDump
798//purpose : To dump the active view snapshot to image file
7fd59977 799//==============================================================================
34db9c00 800static Standard_Integer VDump (Draw_Interpretor& theDI,
801 Standard_Integer theArgNb,
802 Standard_CString* theArgVec)
7fd59977 803{
34db9c00 804 if (theArgNb < 2)
7fd59977 805 {
34db9c00 806 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
7fd59977 807 return 1;
808 }
809
34db9c00 810 Standard_Integer anArgIter = 1;
811 Standard_CString aFilePath = theArgVec[anArgIter++];
812 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
813 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
f978241f 814 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
34db9c00 815 Standard_Integer aWidth = 0;
816 Standard_Integer aHeight = 0;
817 for (; anArgIter < theArgNb; ++anArgIter)
7fd59977 818 {
34db9c00 819 TCollection_AsciiString anArg (theArgVec[anArgIter]);
820 anArg.LowerCase();
f978241f 821 if (anArg == "-buffer")
7fd59977 822 {
f978241f 823 if (++anArgIter >= theArgNb)
824 {
825 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
826 return 1;
827 }
828
829 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
830 aBufArg.LowerCase();
831 if (aBufArg == "rgba")
832 {
833 aBufferType = Graphic3d_BT_RGBA;
834 }
835 else if (aBufArg == "rgb")
836 {
837 aBufferType = Graphic3d_BT_RGB;
838 }
839 else if (aBufArg == "depth")
840 {
841 aBufferType = Graphic3d_BT_Depth;
842 }
843 else
844 {
845 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
846 return 1;
847 }
7fd59977 848 }
f978241f 849 else if (anArg == "-stereo")
7fd59977 850 {
f978241f 851 if (++anArgIter >= theArgNb)
852 {
853 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
854 return 1;
855 }
856
857 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
858 aStereoArg.LowerCase();
859 if (aStereoArg == "l"
860 || aStereoArg == "left")
861 {
862 aStereoOpts = V3d_SDO_LEFT_EYE;
863 }
864 else if (aStereoArg == "r"
865 || aStereoArg == "right")
866 {
867 aStereoOpts = V3d_SDO_RIGHT_EYE;
868 }
869 else if (aStereoArg == "mono")
870 {
871 aStereoOpts = V3d_SDO_MONO;
872 }
873 else if (aStereoArg == "blended"
874 || aStereoArg == "blend"
875 || aStereoArg == "stereo")
876 {
877 aStereoOpts = V3d_SDO_BLENDED;
878 }
879 else if (aStereoArg == "sbs"
880 || aStereoArg == "sidebyside")
881 {
882 aStereoPair = ViewerTest_SP_SideBySide;
883 }
884 else if (aStereoArg == "ou"
885 || aStereoArg == "overunder")
886 {
887 aStereoPair = ViewerTest_SP_OverUnder;
888 }
889 else
890 {
891 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
892 return 1;
893 }
7fd59977 894 }
f978241f 895 else if (anArg == "-rgba"
896 || anArg == "rgba")
34db9c00 897 {
f978241f 898 aBufferType = Graphic3d_BT_RGBA;
34db9c00 899 }
f978241f 900 else if (anArg == "-rgb"
901 || anArg == "rgb")
34db9c00 902 {
f978241f 903 aBufferType = Graphic3d_BT_RGB;
34db9c00 904 }
f978241f 905 else if (anArg == "-depth"
906 || anArg == "depth")
34db9c00 907 {
f978241f 908 aBufferType = Graphic3d_BT_Depth;
34db9c00 909 }
f978241f 910
911 else if (anArg == "-width"
912 || anArg == "width"
913 || anArg == "sizex")
34db9c00 914 {
f978241f 915 if (aWidth != 0)
34db9c00 916 {
917 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
918 return 1;
919 }
920 else if (++anArgIter >= theArgNb)
921 {
922 std::cout << "Error: integer value is expected right after 'width'\n";
923 return 1;
924 }
925 aWidth = Draw::Atoi (theArgVec[anArgIter]);
926 }
f978241f 927 else if (anArg == "-height"
928 || anArg == "height"
929 || anArg == "-sizey")
34db9c00 930 {
931 if (aHeight != 0)
932 {
933 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
934 return 1;
935 }
34db9c00 936 else if (++anArgIter >= theArgNb)
937 {
f978241f 938 std::cout << "Error: integer value is expected right after 'height'\n";
34db9c00 939 return 1;
940 }
34db9c00 941 aHeight = Draw::Atoi (theArgVec[anArgIter]);
942 }
943 else
944 {
945 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
946 return 1;
947 }
7fd59977 948 }
34db9c00 949 if ((aWidth <= 0 && aHeight > 0)
950 || (aWidth > 0 && aHeight <= 0))
7fd59977 951 {
34db9c00 952 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
85e096c3 953 return 1;
954 }
955
34db9c00 956 Handle(V3d_View) aView = ViewerTest::CurrentView();
957 if (aView.IsNull())
85e096c3 958 {
34db9c00 959 std::cout << "Error: cannot find an active view!\n";
960 return 1;
7fd59977 961 }
85e096c3 962
34db9c00 963 if (aWidth <= 0 || aHeight <= 0)
b5ac8292 964 {
f978241f 965 aView->Window()->Size (aWidth, aHeight);
966 }
967
968 Image_AlienPixMap aPixMap;
969
970 bool isBigEndian = Image_PixMap::IsBigEndianHost();
971 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
972 switch (aBufferType)
973 {
974 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
975 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
976 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
977 }
978
979 switch (aStereoPair)
980 {
981 case ViewerTest_SP_Single:
b5ac8292 982 {
f978241f 983 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
984 {
985 theDI << "Fail: view dump failed!\n";
986 return 0;
987 }
988 else if (aPixMap.SizeX() != Standard_Size(aWidth)
989 || aPixMap.SizeY() != Standard_Size(aHeight))
990 {
991 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
992 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
993 }
994 break;
b5ac8292 995 }
f978241f 996 case ViewerTest_SP_SideBySide:
b5ac8292 997 {
f978241f 998 if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
999 {
1000 theDI << "Fail: not enough memory for image allocation!\n";
1001 return 0;
1002 }
1003
1004 Image_PixMap aPixMapL, aPixMapR;
1005 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1006 aWidth, aHeight, aPixMap.SizeRowBytes());
1007 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
1008 aWidth, aHeight, aPixMap.SizeRowBytes());
1009 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1010 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
1011 )
34db9c00 1012 {
1013 theDI << "Fail: view dump failed!\n";
f978241f 1014 return 0;
34db9c00 1015 }
f978241f 1016 break;
b5ac8292 1017 }
f978241f 1018 case ViewerTest_SP_OverUnder:
1019 {
1020 if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
1021 {
1022 theDI << "Fail: not enough memory for image allocation!\n";
1023 return 0;
1024 }
b5ac8292 1025
f978241f 1026 Image_PixMap aPixMapL, aPixMapR;
1027 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
1028 aWidth, aHeight, aPixMap.SizeRowBytes());
1029 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
1030 aWidth, aHeight, aPixMap.SizeRowBytes());
1031 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1032 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
1033 {
1034 theDI << "Fail: view dump failed!\n";
1035 return 0;
1036 }
1037 break;
1038 }
7fd59977 1039 }
85e096c3 1040
34db9c00 1041 if (!aPixMap.Save (aFilePath))
85e096c3 1042 {
34db9c00 1043 theDI << "Fail: image can not be saved!\n";
85e096c3 1044 }
1045 return 0;
7fd59977 1046}
1047
7fd59977 1048//==============================================================================
1049//function : Displays,Erase...
1050//purpose :
1051//Draw arg :
1052//==============================================================================
1053static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
1054 const Standard_Integer Mode,
1055 const Standard_Integer TypeOfOperation,
1056 const Standard_Boolean Upd)
1057{
1058 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1059
1060 switch(TypeOfOperation){
1061 case 1:
1062 Ctx->Display(IO,Mode,Upd);
1063 break;
1064 case 2:{
eb4320f2 1065 Ctx->Erase(IO,Upd);
7fd59977 1066 break;
1067 }
1068 case 3:{
1069 if(IO.IsNull())
1070 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
1071 else
1072 Ctx->SetDisplayMode(IO,Mode,Upd);
1073 break;
1074 }
1075 case 4:{
1076 if(IO.IsNull())
1077 Ctx->SetDisplayMode(0,Upd);
1078 else
1079 Ctx->UnsetDisplayMode(IO,Upd);
1080 break;
1081 }
1082 }
1083 return 0;
1084}
1085
1086//=======================================================================
1087//function :
1088//purpose :
1089//=======================================================================
1090static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1091{
1092
1093 TCollection_AsciiString name;
1094 if(argc>3)
1095 return 1;
1096 // display others presentations
1097 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1098 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1099 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1100 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1101
1102 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1103
1104 //unset displaymode.. comportement particulier...
1105 if(TypeOfOperation==4){
1106 if(argc==1){
c3282ec1 1107 if(Ctx->NbSelected()==0){
7fd59977 1108 Handle(AIS_InteractiveObject) IO;
1109 VwrTst_DispErase(IO,-1,4,Standard_False);
1110 }
7fd59977 1111 else{
1112 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
c3282ec1 1113 VwrTst_DispErase(Ctx->SelectedInteractive(),-1,4,Standard_False);}
7fd59977 1114 Ctx->UpdateCurrentViewer();
1115 }
1116 else{
1117 Handle(AIS_InteractiveObject) IO;
1118 name = argv[1];
1119 if(GetMapOfAIS().IsBound2(name)){
1120 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1121 if (!IO.IsNull())
1122 VwrTst_DispErase(IO,-1,4,Standard_True);
1123 }
1124 }
1125 }
1126 else if(argc==2){
91322f44 1127 Standard_Integer Dmode = Draw::Atoi(argv[1]);
c3282ec1 1128 if(Ctx->NbSelected()==0 && TypeOfOperation==3){
7fd59977 1129 Handle(AIS_InteractiveObject) IO;
1130 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1131 }
1132 if(!Ctx->HasOpenedContext()){
1133 // set/unset display mode sur le Contexte...
c3282ec1 1134 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1135 VwrTst_DispErase(Ctx->SelectedInteractive(),Dmode,TypeOfOperation,Standard_False);
7fd59977 1136 }
1137 Ctx->UpdateCurrentViewer();
1138 }
1139 else{
1140 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
c3282ec1 1141 Ctx->Display(Ctx->SelectedInteractive(),Dmode);
7fd59977 1142 }
1143 }
1144 else{
1145 Handle(AIS_InteractiveObject) IO;
1146 name = argv[1];
1147 if(GetMapOfAIS().IsBound2(name))
1148 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1149 if (!IO.IsNull())
91322f44 1150 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
7fd59977 1151 }
1152 return 0;
1153}
1154
1155
1156//=======================================================================
1157//function :
1158//purpose :
1159//=======================================================================
1160static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1161{
1162 if(argc==1) return 1;
91322f44 1163 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 1164 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1165
c3282ec1 1166 if(argc==2)
1167 {
1168 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1169 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1170 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1171 {
1172 if(On==1)
1173 {
1174 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1175 }
c3282ec1 1176 else
1177 {
1178 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1179 }
1180 }
c3282ec1 1181
7fd59977 1182 Ctx->UpdateCurrentViewer();
1183 }
1184 else {
1185 Handle(AIS_InteractiveObject) IO;
1186 TCollection_AsciiString name = argv[2];
1187 if(GetMapOfAIS().IsBound2(name)){
1188 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
eafb234b 1189 if (!IO.IsNull()) {
7fd59977 1190 if(On==1)
1191 Ctx->SubIntensityOn(IO);
1192 else
1193 Ctx->SubIntensityOff(IO);
eafb234b 1194 }
7fd59977 1195 }
1196 else return 1;
1197 }
1198 return 0;
7fd59977 1199}
7fd59977 1200
ad3217cd 1201//! Auxiliary class to iterate presentations from different collections.
1202class ViewTest_PrsIter
1203{
1204public:
7fd59977 1205
ad3217cd 1206 //! Create and initialize iterator object.
1207 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1208 : mySource (IterSource_All)
1209 {
1210 NCollection_Sequence<TCollection_AsciiString> aNames;
1211 if (!theName.IsEmpty())
1212 aNames.Append (theName);
1213 Init (aNames);
7fd59977 1214 }
ad3217cd 1215
1216 //! Create and initialize iterator object.
1217 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1218 : mySource (IterSource_All)
1219 {
1220 Init (theNames);
7fd59977 1221 }
1222
ad3217cd 1223 //! Initialize the iterator.
1224 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1225 {
1226 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1227 mySeq = theNames;
1228 mySelIter.Nullify();
1229 myCurrent.Nullify();
1230 myCurrentTrs.Nullify();
1231 if (!mySeq.IsEmpty())
1232 {
1233 mySource = IterSource_List;
1234 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
7fd59977 1235 }
c3282ec1 1236 else if (aCtx->NbSelected() > 0)
ad3217cd 1237 {
1238 mySource = IterSource_Selected;
1239 mySelIter = aCtx;
c3282ec1 1240 mySelIter->InitSelected();
ad3217cd 1241 }
1242 else
1243 {
1244 mySource = IterSource_All;
1245 myMapIter.Initialize (GetMapOfAIS());
1246 }
1247 initCurrent();
1248 }
7fd59977 1249
ad3217cd 1250 const TCollection_AsciiString& CurrentName() const
1251 {
1252 return myCurrentName;
1253 }
7fd59977 1254
ad3217cd 1255 const Handle(AIS_InteractiveObject)& Current() const
1256 {
1257 return myCurrent;
1258 }
7fd59977 1259
ad3217cd 1260 const Handle(Standard_Transient)& CurrentTrs() const
1261 {
1262 return myCurrentTrs;
1263 }
1264
1265 //! @return true if iterator points to valid object within collection
1266 Standard_Boolean More() const
1267 {
1268 switch (mySource)
1269 {
1270 case IterSource_All: return myMapIter.More();
1271 case IterSource_List: return mySeqIter.More();
c3282ec1 1272 case IterSource_Selected: return mySelIter->MoreSelected();
ad3217cd 1273 }
1274 return Standard_False;
1275 }
1276
1277 //! Go to the next item.
1278 void Next()
1279 {
1280 myCurrentName.Clear();
1281 myCurrentTrs.Nullify();
1282 myCurrent.Nullify();
1283 switch (mySource)
1284 {
1285 case IterSource_All:
1286 {
1287 myMapIter.Next();
1288 break;
1289 }
1290 case IterSource_List:
1291 {
1292 mySeqIter.Next();
1293 break;
1294 }
1295 case IterSource_Selected:
1296 {
c3282ec1 1297 mySelIter->NextSelected();
ad3217cd 1298 break;
7fd59977 1299 }
1300 }
ad3217cd 1301 initCurrent();
1302 }
7fd59977 1303
ad3217cd 1304private:
7fd59977 1305
ad3217cd 1306 void initCurrent()
1307 {
1308 switch (mySource)
1309 {
1310 case IterSource_All:
7fd59977 1311 {
ad3217cd 1312 if (myMapIter.More())
1313 {
1314 myCurrentName = myMapIter.Key2();
1315 myCurrentTrs = myMapIter.Key1();
1316 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
eafb234b 1317 }
ad3217cd 1318 break;
1319 }
1320 case IterSource_List:
1321 {
1322 if (mySeqIter.More())
1323 {
1324 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1325 {
1326 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1327 return;
1328 }
1329 myCurrentName = mySeqIter.Value();
1330 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1331 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1332 }
1333 break;
1334 }
1335 case IterSource_Selected:
1336 {
c3282ec1 1337 if (mySelIter->MoreSelected())
ad3217cd 1338 {
c3282ec1 1339 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1340 myCurrent = mySelIter->SelectedInteractive();
ad3217cd 1341 }
1342 break;
7fd59977 1343 }
7fd59977 1344 }
1345 }
ad3217cd 1346
1347private:
1348
1349 enum IterSource
1350 {
1351 IterSource_All,
1352 IterSource_List,
1353 IterSource_Selected
1354 };
1355
1356private:
1357
1358 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1359 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1360 NCollection_Sequence<TCollection_AsciiString> mySeq;
1361 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1362
1363 TCollection_AsciiString myCurrentName;//!< current item name
1364 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1365 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1366
1367 IterSource mySource; //!< iterated collection
1368
1369};
7fd59977 1370
1371//==============================================================================
ad3217cd 1372//function : VInteriorStyle
1373//purpose : sets interior style of the a selected or named or displayed shape
7fd59977 1374//==============================================================================
ad3217cd 1375static int VSetInteriorStyle (Draw_Interpretor& theDI,
1376 Standard_Integer theArgNb,
1377 const char** theArgVec)
7fd59977 1378{
ad3217cd 1379 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1380 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1381 if (aCtx.IsNull())
1382 {
1383 std::cerr << "Error: no active view!\n";
1384 return 1;
1385 }
7fd59977 1386
4e18052b 1387 Standard_Integer anArgIter = 1;
ad3217cd 1388 for (; anArgIter < theArgNb; ++anArgIter)
1389 {
4e18052b 1390 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
ad3217cd 1391 {
1392 break;
1393 }
7fd59977 1394 }
ad3217cd 1395 TCollection_AsciiString aName;
1396 if (theArgNb - anArgIter == 2)
1397 {
1398 aName = theArgVec[anArgIter++];
1399 }
1400 else if (theArgNb - anArgIter != 1)
1401 {
1402 std::cout << "Error: wrong number of arguments! See usage:\n";
1403 theDI.PrintHelp (theArgVec[0]);
1404 return 1;
1405 }
1406 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1407 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1408 aStyleArg.LowerCase();
1409 if (aStyleArg == "empty")
1410 {
1411 anInterStyle = 0;
1412 }
1413 else if (aStyleArg == "hollow")
1414 {
1415 anInterStyle = 1;
1416 }
1417 else if (aStyleArg == "hatch")
1418 {
1419 anInterStyle = 2;
1420 }
1421 else if (aStyleArg == "solid")
1422 {
1423 anInterStyle = 3;
1424 }
1425 else if (aStyleArg == "hiddenline")
1426 {
1427 anInterStyle = 4;
1428 }
1429 else
1430 {
1431 anInterStyle = aStyleArg.IntegerValue();
1432 }
1433 if (anInterStyle < Aspect_IS_EMPTY
1434 || anInterStyle > Aspect_IS_HIDDENLINE)
1435 {
1436 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1437 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1438 return 1;
7fd59977 1439 }
1440
ad3217cd 1441 if (!aName.IsEmpty()
1442 && !GetMapOfAIS().IsBound2 (aName))
1443 {
1444 std::cout << "Error: object " << aName << " is not displayed!\n";
1445 return 1;
1446 }
1447
1448 if (aCtx->HasOpenedContext())
1449 {
1450 aCtx->CloseLocalContext();
1451 }
1452 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1453 {
1454 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1455 if (!anIO.IsNull())
1456 {
1457 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1458 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1459 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1460 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1461 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
7fd59977 1462 }
ad3217cd 1463 }
ad3217cd 1464 return 0;
1465}
7fd59977 1466
ad3217cd 1467//! Auxiliary structure for VAspects
1468struct ViewerTest_AspectsChangeSet
1469{
5bffb882 1470 Standard_Integer ToSetVisibility;
1471 Standard_Integer Visibility;
1472
ad3217cd 1473 Standard_Integer ToSetColor;
1474 Quantity_Color Color;
1475
1476 Standard_Integer ToSetLineWidth;
1477 Standard_Real LineWidth;
1478
ac116c22 1479 Standard_Integer ToSetTypeOfLine;
1480 Aspect_TypeOfLine TypeOfLine;
1481
ad3217cd 1482 Standard_Integer ToSetTransparency;
1483 Standard_Real Transparency;
1484
1485 Standard_Integer ToSetMaterial;
1486 Graphic3d_NameOfMaterial Material;
1487 TCollection_AsciiString MatName;
1488
1489 NCollection_Sequence<TopoDS_Shape> SubShapes;
1490
6262338c 1491 Standard_Integer ToSetShowFreeBoundary;
1492 Standard_Integer ToSetFreeBoundaryWidth;
1493 Standard_Real FreeBoundaryWidth;
1494 Standard_Integer ToSetFreeBoundaryColor;
1495 Quantity_Color FreeBoundaryColor;
1496
5ad8c033 1497 Standard_Integer ToEnableIsoOnTriangulation;
1498
1499 Standard_Integer ToSetMaxParamValue;
1500 Standard_Real MaxParamValue;
1501
8a1170ad 1502 Standard_Integer ToSetSensitivity;
1503 Standard_Integer SelectionMode;
1504 Standard_Integer Sensitivity;
1505
ad3217cd 1506 //! Empty constructor
1507 ViewerTest_AspectsChangeSet()
5bffb882 1508 : ToSetVisibility (0),
1509 Visibility (1),
1510 ToSetColor (0),
ad3217cd 1511 Color (DEFAULT_COLOR),
1512 ToSetLineWidth (0),
1513 LineWidth (1.0),
ac116c22 1514 ToSetTypeOfLine (0),
1515 TypeOfLine (Aspect_TOL_SOLID),
ad3217cd 1516 ToSetTransparency (0),
1517 Transparency (0.0),
1518 ToSetMaterial (0),
6262338c 1519 Material (Graphic3d_NOM_DEFAULT),
5ad8c033 1520 ToSetShowFreeBoundary (0),
1521 ToSetFreeBoundaryWidth (0),
1522 FreeBoundaryWidth (1.0),
1523 ToSetFreeBoundaryColor (0),
1524 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1525 ToEnableIsoOnTriangulation (-1),
1526 ToSetMaxParamValue (0),
8a1170ad 1527 MaxParamValue (500000),
1528 ToSetSensitivity (0),
1529 SelectionMode (-1),
1530 Sensitivity (-1) {}
ad3217cd 1531
1532 //! @return true if no changes have been requested
1533 Standard_Boolean IsEmpty() const
1534 {
6262338c 1535 return ToSetVisibility == 0
1536 && ToSetLineWidth == 0
1537 && ToSetTransparency == 0
1538 && ToSetColor == 0
1539 && ToSetMaterial == 0
1540 && ToSetShowFreeBoundary == 0
1541 && ToSetFreeBoundaryColor == 0
5ad8c033 1542 && ToSetFreeBoundaryWidth == 0
8a1170ad 1543 && ToSetMaxParamValue == 0
1544 && ToSetSensitivity == 0;
ad3217cd 1545 }
1546
1547 //! @return true if properties are valid
1548 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1549 {
1550 Standard_Boolean isOk = Standard_True;
5bffb882 1551 if (Visibility != 0 && Visibility != 1)
1552 {
1553 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1554 isOk = Standard_False;
1555 }
ad3217cd 1556 if (LineWidth <= 0.0
1557 || LineWidth > 10.0)
1558 {
1559 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1560 isOk = Standard_False;
7fd59977 1561 }
ad3217cd 1562 if (Transparency < 0.0
1563 || Transparency > 1.0)
1564 {
1565 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1566 isOk = Standard_False;
1567 }
1568 if (theIsSubPart
1569 && ToSetTransparency)
1570 {
1571 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1572 isOk = Standard_False;
7fd59977 1573 }
ad3217cd 1574 if (ToSetMaterial == 1
1575 && Material == Graphic3d_NOM_DEFAULT)
1576 {
1577 std::cout << "Error: unknown material " << MatName << ".\n";
1578 isOk = Standard_False;
1579 }
6262338c 1580 if (FreeBoundaryWidth <= 0.0
1581 || FreeBoundaryWidth > 10.0)
1582 {
1583 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1584 isOk = Standard_False;
1585 }
5ad8c033 1586 if (MaxParamValue < 0.0)
1587 {
1588 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1589 isOk = Standard_False;
1590 }
8a1170ad 1591 if (Sensitivity <= 0 && ToSetSensitivity)
1592 {
1593 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1594 isOk = Standard_False;
1595 }
ad3217cd 1596 return isOk;
7fd59977 1597 }
7fd59977 1598
ad3217cd 1599};
7fd59977 1600
1601//==============================================================================
ad3217cd 1602//function : VAspects
1603//purpose :
7fd59977 1604//==============================================================================
ad3217cd 1605static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1606 Standard_Integer theArgNb,
1607 const char** theArgVec)
7fd59977 1608{
ad3217cd 1609 TCollection_AsciiString aCmdName (theArgVec[0]);
1610 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1611 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1612 if (aCtx.IsNull())
1613 {
1614 std::cerr << "Error: no active view!\n";
1615 return 1;
1616 }
7fd59977 1617
4e18052b 1618 Standard_Integer anArgIter = 1;
6262338c 1619 Standard_Boolean isDefaults = Standard_False;
ad3217cd 1620 NCollection_Sequence<TCollection_AsciiString> aNames;
1621 for (; anArgIter < theArgNb; ++anArgIter)
1622 {
1623 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 1624 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 1625 {
1626 continue;
1627 }
1628 else if (!anArg.IsEmpty()
1629 && anArg.Value (1) != '-')
1630 {
1631 aNames.Append (anArg);
1632 }
1633 else
1634 {
6262338c 1635 if (anArg == "-defaults")
1636 {
1637 isDefaults = Standard_True;
1638 ++anArgIter;
1639 }
ad3217cd 1640 break;
1641 }
1642 }
1643
6262338c 1644 if (!aNames.IsEmpty() && isDefaults)
1645 {
1646 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1647 return 1;
1648 }
1649
ad3217cd 1650 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1651 aChanges.Append (ViewerTest_AspectsChangeSet());
1652 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 1653
ad3217cd 1654 // parse syntax of legacy commands
1655 if (aCmdName == "vsetwidth")
1656 {
1657 if (aNames.IsEmpty()
1658 || !aNames.Last().IsRealValue())
1659 {
1660 std::cout << "Error: not enough arguments!\n";
1661 return 1;
1662 }
1663 aChangeSet->ToSetLineWidth = 1;
1664 aChangeSet->LineWidth = aNames.Last().RealValue();
1665 aNames.Remove (aNames.Length());
7fd59977 1666 }
ad3217cd 1667 else if (aCmdName == "vunsetwidth")
1668 {
1669 aChangeSet->ToSetLineWidth = -1;
1670 }
1671 else if (aCmdName == "vsetcolor")
1672 {
1673 if (aNames.IsEmpty())
1674 {
1675 std::cout << "Error: not enough arguments!\n";
1676 return 1;
1677 }
1678 aChangeSet->ToSetColor = 1;
8316c618 1679
1680 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1681 Standard_Boolean isOk = Standard_False;
1682 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1683 {
1684 aChangeSet->Color = aColor;
1685 aNames.Remove (aNames.Length());
1686 isOk = Standard_True;
1687 }
1688 else if (aNames.Length() >= 3)
1689 {
1690 const TCollection_AsciiString anRgbStr[3] =
1691 {
1692 aNames.Value (aNames.Upper() - 2),
1693 aNames.Value (aNames.Upper() - 1),
1694 aNames.Value (aNames.Upper() - 0)
1695 };
1696 isOk = anRgbStr[0].IsRealValue()
1697 && anRgbStr[1].IsRealValue()
1698 && anRgbStr[2].IsRealValue();
1699 if (isOk)
1700 {
1701 Graphic3d_Vec4d anRgb;
1702 anRgb.x() = anRgbStr[0].RealValue();
1703 anRgb.y() = anRgbStr[1].RealValue();
1704 anRgb.z() = anRgbStr[2].RealValue();
1705 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1706 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1707 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1708 {
1709 std::cout << "Error: RGB color values should be within range 0..1!\n";
1710 return 1;
1711 }
1712 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1713 aNames.Remove (aNames.Length());
1714 aNames.Remove (aNames.Length());
1715 aNames.Remove (aNames.Length());
1716 }
1717 }
1718 if (!isOk)
1719 {
1720 std::cout << "Error: not enough arguments!\n";
1721 return 1;
1722 }
ad3217cd 1723 }
1724 else if (aCmdName == "vunsetcolor")
1725 {
1726 aChangeSet->ToSetColor = -1;
1727 }
1728 else if (aCmdName == "vsettransparency")
1729 {
1730 if (aNames.IsEmpty()
1731 || !aNames.Last().IsRealValue())
1732 {
1733 std::cout << "Error: not enough arguments!\n";
1734 return 1;
1735 }
1736 aChangeSet->ToSetTransparency = 1;
1737 aChangeSet->Transparency = aNames.Last().RealValue();
1738 aNames.Remove (aNames.Length());
1739 }
1740 else if (aCmdName == "vunsettransparency")
1741 {
1742 aChangeSet->ToSetTransparency = -1;
1743 }
1744 else if (aCmdName == "vsetmaterial")
1745 {
1746 if (aNames.IsEmpty())
1747 {
1748 std::cout << "Error: not enough arguments!\n";
1749 return 1;
1750 }
1751 aChangeSet->ToSetMaterial = 1;
1752 aChangeSet->MatName = aNames.Last();
1753 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1754 aNames.Remove (aNames.Length());
1755 }
1756 else if (aCmdName == "vunsetmaterial")
1757 {
1758 aChangeSet->ToSetMaterial = -1;
1759 }
1760 else if (anArgIter >= theArgNb)
1761 {
1762 std::cout << "Error: not enough arguments!\n";
1763 return 1;
7fd59977 1764 }
1765
ad3217cd 1766 if (!aChangeSet->IsEmpty())
1767 {
1768 anArgIter = theArgNb;
1769 }
1770 for (; anArgIter < theArgNb; ++anArgIter)
1771 {
1772 TCollection_AsciiString anArg = theArgVec[anArgIter];
1773 anArg.LowerCase();
1774 if (anArg == "-setwidth"
1775 || anArg == "-setlinewidth")
1776 {
1777 if (++anArgIter >= theArgNb)
1778 {
1779 std::cout << "Error: wrong syntax at " << anArg << "\n";
1780 return 1;
1781 }
1782 aChangeSet->ToSetLineWidth = 1;
1783 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1784 }
ad3217cd 1785 else if (anArg == "-unsetwidth"
1786 || anArg == "-unsetlinewidth")
1787 {
1788 aChangeSet->ToSetLineWidth = -1;
1789 aChangeSet->LineWidth = 1.0;
1790 }
1791 else if (anArg == "-settransp"
0ae61cf3 1792 || anArg == "-settransparency")
ad3217cd 1793 {
1794 if (++anArgIter >= theArgNb)
1795 {
1796 std::cout << "Error: wrong syntax at " << anArg << "\n";
1797 return 1;
1798 }
1799 aChangeSet->ToSetTransparency = 1;
1800 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1801 if (aChangeSet->Transparency >= 0.0
1802 && aChangeSet->Transparency <= Precision::Confusion())
1803 {
1804 aChangeSet->ToSetTransparency = -1;
1805 aChangeSet->Transparency = 0.0;
eafb234b 1806 }
7fd59977 1807 }
5bffb882 1808 else if (anArg == "-setvis"
1809 || anArg == "-setvisibility")
1810 {
1811 if (++anArgIter >= theArgNb)
1812 {
1813 std::cout << "Error: wrong syntax at " << anArg << "\n";
1814 return 1;
1815 }
1816
1817 aChangeSet->ToSetVisibility = 1;
1818 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1819 }
ad3217cd 1820 else if (anArg == "-setalpha")
1821 {
1822 if (++anArgIter >= theArgNb)
7fd59977 1823 {
ad3217cd 1824 std::cout << "Error: wrong syntax at " << anArg << "\n";
1825 return 1;
1826 }
1827 aChangeSet->ToSetTransparency = 1;
1828 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1829 if (aChangeSet->Transparency < 0.0
1830 || aChangeSet->Transparency > 1.0)
1831 {
1832 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1833 return 1;
1834 }
1835 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1836 if (aChangeSet->Transparency >= 0.0
1837 && aChangeSet->Transparency <= Precision::Confusion())
1838 {
1839 aChangeSet->ToSetTransparency = -1;
1840 aChangeSet->Transparency = 0.0;
7fd59977 1841 }
7fd59977 1842 }
ad3217cd 1843 else if (anArg == "-unsettransp"
0ae61cf3 1844 || anArg == "-unsettransparency"
ad3217cd 1845 || anArg == "-unsetalpha"
1846 || anArg == "-opaque")
1847 {
1848 aChangeSet->ToSetTransparency = -1;
1849 aChangeSet->Transparency = 0.0;
1850 }
1851 else if (anArg == "-setcolor")
1852 {
8316c618 1853 Standard_Integer aNbComps = 0;
1854 Standard_Integer aCompIter = anArgIter + 1;
1855 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
ad3217cd 1856 {
8316c618 1857 if (theArgVec[aCompIter][0] == '-')
1858 {
1859 break;
1860 }
1861 }
1862 switch (aNbComps)
1863 {
1864 case 1:
1865 {
1866 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1867 Standard_CString aName = theArgVec[anArgIter + 1];
1868 if (!Quantity_Color::ColorFromName (aName, aColor))
1869 {
1870 std::cout << "Error: unknown color name '" << aName << "'\n";
1871 return 1;
1872 }
1873 aChangeSet->Color = aColor;
1874 break;
1875 }
1876 case 3:
1877 {
1878 Graphic3d_Vec3d anRgb;
1879 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1880 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1881 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1882 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1883 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1884 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1885 {
1886 std::cout << "Error: RGB color values should be within range 0..1!\n";
1887 return 1;
1888 }
1889 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1890 break;
1891 }
1892 default:
1893 {
1894 std::cout << "Error: wrong syntax at " << anArg << "\n";
1895 return 1;
1896 }
7fd59977 1897 }
ad3217cd 1898 aChangeSet->ToSetColor = 1;
8316c618 1899 anArgIter += aNbComps;
7fd59977 1900 }
ac116c22 1901 else if (anArg == "-setlinetype")
1902 {
1903 if (++anArgIter >= theArgNb)
1904 {
1905 std::cout << "Error: wrong syntax at " << anArg << "\n";
1906 return 1;
1907 }
1908
1909 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1910 aValue.LowerCase();
1911
1912 if (aValue.IsEqual ("solid"))
1913 {
1914 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1915 }
1916 else if (aValue.IsEqual ("dot"))
1917 {
1918 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1919 }
1920 else if (aValue.IsEqual ("dash"))
1921 {
1922 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1923 }
1924 else if (aValue.IsEqual ("dotdash"))
1925 {
1926 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1927 }
1928 else
1929 {
1930 std::cout << "Error: wrong syntax at " << anArg << "\n";
1931 return 1;
1932 }
1933
1934 aChangeSet->ToSetTypeOfLine = 1;
1935 }
1936 else if (anArg == "-unsetlinetype")
1937 {
1938 aChangeSet->ToSetTypeOfLine = -1;
1939 }
ad3217cd 1940 else if (anArg == "-unsetcolor")
1941 {
1942 aChangeSet->ToSetColor = -1;
1943 aChangeSet->Color = DEFAULT_COLOR;
1944 }
1945 else if (anArg == "-setmat"
1946 || anArg == "-setmaterial")
1947 {
1948 if (++anArgIter >= theArgNb)
1949 {
1950 std::cout << "Error: wrong syntax at " << anArg << "\n";
1951 return 1;
1952 }
1953 aChangeSet->ToSetMaterial = 1;
1954 aChangeSet->MatName = theArgVec[anArgIter];
1955 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1956 }
1957 else if (anArg == "-unsetmat"
1958 || anArg == "-unsetmaterial")
1959 {
1960 aChangeSet->ToSetMaterial = -1;
1961 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1962 }
1963 else if (anArg == "-subshape"
1964 || anArg == "-subshapes")
1965 {
6262338c 1966 if (isDefaults)
1967 {
1968 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1969 return 1;
1970 }
1971
ad3217cd 1972 if (aNames.IsEmpty())
1973 {
1974 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1975 return 1;
1976 }
7fd59977 1977
ad3217cd 1978 aChanges.Append (ViewerTest_AspectsChangeSet());
1979 aChangeSet = &aChanges.ChangeLast();
7fd59977 1980
ad3217cd 1981 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1982 {
1983 Standard_CString aSubShapeName = theArgVec[anArgIter];
1984 if (*aSubShapeName == '-')
1985 {
1986 --anArgIter;
1987 break;
1988 }
7fd59977 1989
ad3217cd 1990 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1991 if (aSubShape.IsNull())
1992 {
1993 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1994 return 1;
1995 }
1996 aChangeSet->SubShapes.Append (aSubShape);
1997 }
7fd59977 1998
ad3217cd 1999 if (aChangeSet->SubShapes.IsEmpty())
2000 {
2001 std::cerr << "Error: empty list is specified after -subshapes!\n";
2002 return 1;
2003 }
2004 }
6262338c 2005 else if (anArg == "-freeboundary"
2006 || anArg == "-fb")
2007 {
2008 if (++anArgIter >= theArgNb)
2009 {
2010 std::cout << "Error: wrong syntax at " << anArg << "\n";
2011 return 1;
2012 }
2013 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2014 aValue.LowerCase();
2015 if (aValue == "on"
2016 || aValue == "1")
2017 {
2018 aChangeSet->ToSetShowFreeBoundary = 1;
2019 }
2020 else if (aValue == "off"
2021 || aValue == "0")
2022 {
2023 aChangeSet->ToSetShowFreeBoundary = -1;
2024 }
2025 else
2026 {
2027 std::cout << "Error: wrong syntax at " << anArg << "\n";
2028 return 1;
2029 }
2030 }
2031 else if (anArg == "-setfreeboundarywidth"
2032 || anArg == "-setfbwidth")
2033 {
2034 if (++anArgIter >= theArgNb)
2035 {
2036 std::cout << "Error: wrong syntax at " << anArg << "\n";
2037 return 1;
2038 }
2039 aChangeSet->ToSetFreeBoundaryWidth = 1;
2040 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2041 }
2042 else if (anArg == "-unsetfreeboundarywidth"
2043 || anArg == "-unsetfbwidth")
2044 {
2045 aChangeSet->ToSetFreeBoundaryWidth = -1;
2046 aChangeSet->FreeBoundaryWidth = 1.0;
2047 }
2048 else if (anArg == "-setfreeboundarycolor"
2049 || anArg == "-setfbcolor")
2050 {
2051 Standard_Integer aNbComps = 0;
2052 Standard_Integer aCompIter = anArgIter + 1;
2053 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2054 {
2055 if (theArgVec[aCompIter][0] == '-')
2056 {
2057 break;
2058 }
2059 }
2060 switch (aNbComps)
2061 {
2062 case 1:
2063 {
2064 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2065 Standard_CString aName = theArgVec[anArgIter + 1];
2066 if (!Quantity_Color::ColorFromName (aName, aColor))
2067 {
2068 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2069 return 1;
2070 }
2071 aChangeSet->FreeBoundaryColor = aColor;
2072 break;
2073 }
2074 case 3:
2075 {
2076 Graphic3d_Vec3d anRgb;
2077 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2078 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2079 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2080 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2081 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2082 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2083 {
2084 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2085 return 1;
2086 }
2087 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2088 break;
2089 }
2090 default:
2091 {
2092 std::cout << "Error: wrong syntax at " << anArg << "\n";
2093 return 1;
2094 }
2095 }
2096 aChangeSet->ToSetFreeBoundaryColor = 1;
2097 anArgIter += aNbComps;
2098 }
2099 else if (anArg == "-unsetfreeboundarycolor"
2100 || anArg == "-unsetfbcolor")
2101 {
2102 aChangeSet->ToSetFreeBoundaryColor = -1;
2103 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2104 }
ad3217cd 2105 else if (anArg == "-unset")
2106 {
5bffb882 2107 aChangeSet->ToSetVisibility = 1;
2108 aChangeSet->Visibility = 1;
ad3217cd 2109 aChangeSet->ToSetLineWidth = -1;
2110 aChangeSet->LineWidth = 1.0;
ac116c22 2111 aChangeSet->ToSetTypeOfLine = -1;
2112 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
ad3217cd 2113 aChangeSet->ToSetTransparency = -1;
2114 aChangeSet->Transparency = 0.0;
2115 aChangeSet->ToSetColor = -1;
2116 aChangeSet->Color = DEFAULT_COLOR;
2117 aChangeSet->ToSetMaterial = -1;
2118 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
6262338c 2119 aChangeSet->ToSetShowFreeBoundary = -1;
2120 aChangeSet->ToSetFreeBoundaryColor = -1;
2121 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2122 aChangeSet->ToSetFreeBoundaryWidth = -1;
2123 aChangeSet->FreeBoundaryWidth = 1.0;
7fd59977 2124 }
5ad8c033 2125 else if (anArg == "-isoontriangulation"
2126 || anArg == "-isoontriang")
2127 {
2128 if (++anArgIter >= theArgNb)
2129 {
2130 std::cout << "Error: wrong syntax at " << anArg << "\n";
2131 return 1;
2132 }
2133 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2134 aValue.LowerCase();
2135 if (aValue == "on"
2136 || aValue == "1")
2137 {
2138 aChangeSet->ToEnableIsoOnTriangulation = 1;
2139 }
2140 else if (aValue == "off"
2141 || aValue == "0")
2142 {
2143 aChangeSet->ToEnableIsoOnTriangulation = 0;
2144 }
2145 else
2146 {
2147 std::cout << "Error: wrong syntax at " << anArg << "\n";
2148 return 1;
2149 }
2150 }
2151 else if (anArg == "-setmaxparamvalue")
2152 {
2153 if (++anArgIter >= theArgNb)
2154 {
2155 std::cout << "Error: wrong syntax at " << anArg << "\n";
2156 return 1;
2157 }
2158 aChangeSet->ToSetMaxParamValue = 1;
2159 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2160 }
8a1170ad 2161 else if (anArg == "-setsensitivity")
2162 {
2163 if (isDefaults)
2164 {
2165 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2166 return 1;
2167 }
2168
2169 if (aNames.IsEmpty())
2170 {
2171 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2172 return 1;
2173 }
2174
2175 if (anArgIter + 2 >= theArgNb)
2176 {
2177 std::cout << "Error: wrong syntax at " << anArg << "\n";
2178 return 1;
2179 }
2180 aChangeSet->ToSetSensitivity = 1;
2181 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2182 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2183 }
7fd59977 2184 else
ad3217cd 2185 {
2186 std::cout << "Error: wrong syntax at " << anArg << "\n";
2187 return 1;
2188 }
7fd59977 2189 }
99c56d44 2190
ad3217cd 2191 Standard_Boolean isFirst = Standard_True;
2192 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2193 aChangesIter.More(); aChangesIter.Next())
2194 {
2195 if (!aChangesIter.Value().Validate (!isFirst))
2196 {
2197 return 1;
2198 }
2199 isFirst = Standard_False;
99c56d44 2200 }
99c56d44 2201
ad3217cd 2202 if (aCtx->HasOpenedContext())
2203 {
2204 aCtx->CloseLocalContext();
99c56d44 2205 }
6262338c 2206
2207 // special case for -defaults parameter.
2208 // all changed values will be set to DefaultDrawer.
2209 if (isDefaults)
2210 {
2211 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2212
2213 if (aChangeSet->ToSetLineWidth != 0)
2214 {
2215 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2216 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2217 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2218 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2219 }
2220 if (aChangeSet->ToSetColor != 0)
2221 {
2222 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2223 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2224 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2225 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2226 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2227 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2228 }
ac116c22 2229 if (aChangeSet->ToSetTypeOfLine != 0)
2230 {
2231 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2232 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2233 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2234 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2235 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2236 }
6262338c 2237 if (aChangeSet->ToSetTransparency != 0)
2238 {
2239 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2240 }
2241 if (aChangeSet->ToSetMaterial != 0)
2242 {
2243 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2244 }
2245 if (aChangeSet->ToSetShowFreeBoundary == 1)
2246 {
2247 aDrawer->SetFreeBoundaryDraw (Standard_True);
2248 }
2249 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2250 {
2251 aDrawer->SetFreeBoundaryDraw (Standard_False);
2252 }
2253 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2254 {
2255 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2256 }
2257 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2258 {
2259 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2260 }
5ad8c033 2261 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2262 {
2263 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2264 }
2265 if (aChangeSet->ToSetMaxParamValue != 0)
2266 {
2267 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2268 }
6262338c 2269
2270 // redisplay all objects in context
2271 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2272 {
2273 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2274 if (!aPrs.IsNull())
2275 {
2276 aCtx->Redisplay (aPrs, Standard_False);
2277 }
2278 }
2279 return 0;
2280 }
2281
ad3217cd 2282 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2283 {
6262338c 2284 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2285 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2286 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 2287 Handle(AIS_ColoredShape) aColoredPrs;
2288 Standard_Boolean toDisplay = Standard_False;
6262338c 2289 Standard_Boolean toRedisplay = Standard_False;
5bffb882 2290 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 2291 {
2292 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2293 if (aShapePrs.IsNull())
2294 {
2295 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2296 return 1;
2297 }
2298 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2299 if (aColoredPrs.IsNull())
2300 {
2301 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2302 aCtx->Remove (aShapePrs, Standard_False);
2303 GetMapOfAIS().UnBind2 (aName);
2304 GetMapOfAIS().Bind (aColoredPrs, aName);
2305 toDisplay = Standard_True;
2306 aShapePrs = aColoredPrs;
2307 aPrs = aColoredPrs;
2308 }
2309 }
99c56d44 2310
ad3217cd 2311 if (!aPrs.IsNull())
2312 {
2313 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2314 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2315 if (aChangeSet->ToSetVisibility == 1)
2316 {
2317 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2318 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2319 }
2320 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2321 {
2322 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2323 }
2324 else if (aChangeSet->ToSetMaterial == -1)
2325 {
2326 aCtx->UnsetMaterial (aPrs, Standard_False);
2327 }
2328 if (aChangeSet->ToSetColor == 1)
2329 {
2330 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2331 }
2332 else if (aChangeSet->ToSetColor == -1)
2333 {
2334 aCtx->UnsetColor (aPrs, Standard_False);
2335 }
2336 if (aChangeSet->ToSetTransparency == 1)
2337 {
2338 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2339 }
2340 else if (aChangeSet->ToSetTransparency == -1)
2341 {
2342 aCtx->UnsetTransparency (aPrs, Standard_False);
2343 }
2344 if (aChangeSet->ToSetLineWidth == 1)
2345 {
2346 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2347 }
2348 else if (aChangeSet->ToSetLineWidth == -1)
2349 {
2350 aCtx->UnsetWidth (aPrs, Standard_False);
2351 }
5ad8c033 2352 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2353 {
2354 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2355 toRedisplay = Standard_True;
2356 }
8a1170ad 2357 else if (aChangeSet->ToSetSensitivity != 0)
2358 {
2359 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2360 }
6262338c 2361 if (!aDrawer.IsNull())
2362 {
2363 if (aChangeSet->ToSetShowFreeBoundary == 1)
2364 {
2365 aDrawer->SetFreeBoundaryDraw (Standard_True);
2366 toRedisplay = Standard_True;
2367 }
2368 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2369 {
2370 aDrawer->SetFreeBoundaryDraw (Standard_False);
2371 toRedisplay = Standard_True;
2372 }
2373 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2374 {
2375 Handle(Prs3d_LineAspect) aBoundaryAspect =
2376 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2377 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2378 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2379 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2380 toRedisplay = Standard_True;
2381 }
2382 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2383 {
2384 Handle(Prs3d_LineAspect) aBoundaryAspect =
2385 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2386 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2387 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2388 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2389 toRedisplay = Standard_True;
2390 }
ac116c22 2391 if (aChangeSet->ToSetTypeOfLine != 0)
2392 {
2393 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2394 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2395 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2396 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2397 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2398 toRedisplay = Standard_True;
2399 }
5ad8c033 2400 if (aChangeSet->ToSetMaxParamValue != 0)
2401 {
2402 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2403 }
6262338c 2404 }
99c56d44 2405
ad3217cd 2406 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2407 {
2408 aChangeSet = &aChangesIter.ChangeValue();
2409 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2410 aSubShapeIter.More(); aSubShapeIter.Next())
2411 {
2412 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2413 if (aChangeSet->ToSetVisibility == 1)
2414 {
2415 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2416 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2417 }
ad3217cd 2418 if (aChangeSet->ToSetColor == 1)
2419 {
2420 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2421 }
2422 if (aChangeSet->ToSetLineWidth == 1)
2423 {
2424 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2425 }
2426 if (aChangeSet->ToSetColor == -1
2427 || aChangeSet->ToSetLineWidth == -1)
2428 {
2429 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2430 }
5ad8c033 2431 if (aChangeSet->ToSetMaxParamValue != 0)
2432 {
2433 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2434 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2435 }
8a1170ad 2436 if (aChangeSet->ToSetSensitivity != 0)
2437 {
2438 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2439 }
ad3217cd 2440 }
2441 }
2442 if (toDisplay)
2443 {
2444 aCtx->Display (aPrs, Standard_False);
2445 }
6262338c 2446 if (toRedisplay)
2447 {
2448 aCtx->Redisplay (aPrs, Standard_False);
2449 }
ad3217cd 2450 else if (!aColoredPrs.IsNull())
2451 {
36132a2e 2452 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2453 }
99c56d44 2454 }
ad3217cd 2455 }
99c56d44 2456 return 0;
2457}
2458
7fd59977 2459//==============================================================================
2460//function : VDonly2
2461//author : ege
2462//purpose : Display only a selected or named object
519d35d8 2463// if there is no selected or named object s, nothing is done
7fd59977 2464//==============================================================================
519d35d8 2465static int VDonly2 (Draw_Interpretor& ,
2466 Standard_Integer theArgNb,
2467 const char** theArgVec)
7fd59977 2468{
519d35d8 2469 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2470 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2471 if (aCtx.IsNull())
2472 {
2473 std::cerr << "Error: no active view!\n";
7fd59977 2474 return 1;
519d35d8 2475 }
7fd59977 2476
519d35d8 2477 if (aCtx->HasOpenedContext())
2478 {
2479 aCtx->CloseLocalContext();
2480 }
7fd59977 2481
519d35d8 2482 Standard_Integer anArgIter = 1;
2483 for (; anArgIter < theArgNb; ++anArgIter)
2484 {
4e18052b 2485 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2486 {
2487 break;
2488 }
2489 }
7fd59977 2490
519d35d8 2491 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2492 if (anArgIter >= theArgNb)
2493 {
2494 // display only selected objects
c3282ec1 2495 if (aCtx->NbSelected() < 1)
519d35d8 2496 {
2497 return 0;
7fd59977 2498 }
2499
c3282ec1 2500 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
519d35d8 2501 {
c3282ec1 2502 aDispSet.Add (aCtx->SelectedInteractive());
519d35d8 2503 }
2504 }
2505 else
2506 {
2507 // display only specified objects
2508 for (; anArgIter < theArgNb; ++anArgIter)
2509 {
2510 TCollection_AsciiString aName = theArgVec[anArgIter];
2511 if (GetMapOfAIS().IsBound2 (aName))
2512 {
d09dda09 2513 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2514 if (!aShape.IsNull())
519d35d8 2515 {
519d35d8 2516 aCtx->Display (aShape, Standard_False);
d09dda09 2517 aDispSet.Add (aShape);
519d35d8 2518 }
7fd59977 2519 }
2520 }
7fd59977 2521 }
519d35d8 2522
2523 // weed out other objects
2524 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2525 {
2526 if (aDispSet.Contains (anIter.Key1()))
2527 {
2528 continue;
2529 }
2530
d09dda09 2531 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2532 if (aShape.IsNull())
519d35d8 2533 {
519d35d8 2534 aCtx->Erase (aShape, Standard_False);
2535 }
519d35d8 2536 }
7fd59977 2537 return 0;
2538}
2539
eef7fc64 2540//==============================================================================
2541//function : VRemove
2542//purpose : Removes selected or named objects.
2543// If there is no selected or named objects,
2544// all objects in the viewer can be removed with argument -all.
2545// If -context is in arguments, the object is not deleted from the map of
2546// objects (deleted only from the current context).
2547//==============================================================================
2548int VRemove (Draw_Interpretor& theDI,
519d35d8 2549 Standard_Integer theArgNb,
2550 const char** theArgVec)
eef7fc64 2551{
4e18052b 2552 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2553 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2554 if (aCtx.IsNull())
eef7fc64 2555 {
b6d587e3 2556 std::cerr << "Error: no active view!\n";
eef7fc64 2557 return 1;
2558 }
2559
4e18052b 2560 Standard_Boolean isContextOnly = Standard_False;
2561 Standard_Boolean toRemoveAll = Standard_False;
2562 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2563 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2564
2565 Standard_Integer anArgIter = 1;
2566 for (; anArgIter < theArgNb; ++anArgIter)
2567 {
2568 TCollection_AsciiString anArg = theArgVec[anArgIter];
2569 anArg.LowerCase();
2570 if (anArg == "-context")
2571 {
2572 isContextOnly = Standard_True;
2573 }
2574 else if (anArg == "-all")
2575 {
2576 toRemoveAll = Standard_True;
2577 }
b7cd4ba7 2578 else if (anArg == "-noinfo")
2579 {
2580 toPrintInfo = Standard_False;
2581 }
b6d587e3 2582 else if (anArg == "-local")
2583 {
2584 toRemoveLocal = Standard_True;
2585 }
2586 else if (anUpdateTool.parseRedrawMode (anArg))
2587 {
2588 continue;
2589 }
2590 else
519d35d8 2591 {
2592 break;
2593 }
2594 }
2595 if (toRemoveAll
2596 && anArgIter < theArgNb)
2597 {
b6d587e3 2598 std::cerr << "Error: wrong syntax!\n";
2599 return 1;
2600 }
2601
2602 if (toRemoveLocal && !aCtx->HasOpenedContext())
2603 {
2604 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2605 return 1;
2606 }
b6d587e3 2607 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2608 {
2609 aCtx->CloseAllContexts (Standard_False);
2610 }
519d35d8 2611
eef7fc64 2612 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2613 if (toRemoveAll)
eef7fc64 2614 {
2615 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2616 anIter.More(); anIter.Next())
2617 {
2618 anIONameList.Append (anIter.Key2());
2619 }
2620 }
519d35d8 2621 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2622 {
519d35d8 2623 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2624 {
519d35d8 2625 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2626 if (!GetMapOfAIS().IsBound2 (aName))
2627 {
2628 theDI << aName.ToCString() << " was not bound to some object.\n";
2629 continue;
2630 }
2631
d09dda09 2632 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2633 if (anIO->GetContext() != aCtx)
eef7fc64 2634 {
d09dda09 2635 theDI << aName.ToCString() << " was not displayed in current context.\n";
2636 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 2637 continue;
2638 }
2639
d09dda09 2640 anIONameList.Append (aName);
2641 continue;
eef7fc64 2642 }
2643 }
c3282ec1 2644 else if (aCtx->NbSelected() > 0)
eef7fc64 2645 {
2646 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2647 anIter.More(); anIter.Next())
2648 {
2649 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
c3282ec1 2650 if (!aCtx->IsSelected (anIO))
eef7fc64 2651 {
eef7fc64 2652 continue;
2653 }
2654
d09dda09 2655 anIONameList.Append (anIter.Key2());
2656 continue;
eef7fc64 2657 }
2658 }
2659
2660 // Unbind all removed objects from the map of displayed IO.
2661 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2662 anIter.More(); anIter.Next())
2663 {
519d35d8 2664 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
d09dda09 2665 aCtx->Remove (anIO, Standard_False);
2666 if (toPrintInfo)
519d35d8 2667 {
d09dda09 2668 theDI << anIter.Value().ToCString() << " was removed\n";
519d35d8 2669 }
519d35d8 2670 if (!isContextOnly)
2671 {
2672 GetMapOfAIS().UnBind2 (anIter.Value());
2673 }
2674 }
b6d587e3 2675
2676 // Close local context if it is empty
2677 TColStd_MapOfTransient aLocalIO;
2678 if (aCtx->HasOpenedContext()
2679 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2680 {
2681 aCtx->CloseAllContexts (Standard_False);
2682 }
2683
eef7fc64 2684 return 0;
2685}
2686
7fd59977 2687//==============================================================================
b514beda 2688//function : VErase
2689//purpose : Erase some selected or named objects
7fd59977 2690// if there is no selected or named objects, the whole viewer is erased
7fd59977 2691//==============================================================================
b514beda 2692int VErase (Draw_Interpretor& theDI,
2693 Standard_Integer theArgNb,
2694 const char** theArgVec)
7fd59977 2695{
a1954302 2696 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2697 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2698 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2699 if (aCtx.IsNull())
b514beda 2700 {
b6d587e3 2701 std::cerr << "Error: no active view!\n";
7fd59977 2702 return 1;
b514beda 2703 }
519d35d8 2704
519d35d8 2705 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2706
2707 Standard_Integer anArgIter = 1;
a272ed94 2708 Standard_Boolean toEraseLocal = Standard_False;
2709 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2710 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2711 for (; anArgIter < theArgNb; ++anArgIter)
2712 {
b6d587e3 2713 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2714 anArgCase.LowerCase();
2715 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2716 {
b6d587e3 2717 continue;
2718 }
2719 else if (anArgCase == "-local")
2720 {
2721 toEraseLocal = Standard_True;
2722 }
a272ed94 2723 else if (anArgCase == "-view"
2724 || anArgCase == "-inview")
2725 {
2726 toEraseInView = Standard_True;
2727 }
b6d587e3 2728 else
2729 {
2730 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2731 }
2732 }
2733
b6d587e3 2734 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2735 {
b6d587e3 2736 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2737 return 1;
2738 }
7fd59977 2739
b6d587e3 2740 if (toEraseLocal && !aCtx->HasOpenedContext())
2741 {
2742 std::cerr << "Error: local selection context is not open.\n";
2743 return 1;
2744 }
2745 else if (!toEraseLocal && aCtx->HasOpenedContext())
2746 {
2747 aCtx->CloseAllContexts (Standard_False);
2748 }
2749
2750 if (!aNamesOfEraseIO.IsEmpty())
2751 {
2752 // Erase named objects
2753 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2754 {
b6d587e3 2755 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2756 if (!GetMapOfAIS().IsBound2 (aName))
2757 {
2758 continue;
2759 }
7fd59977 2760
b514beda 2761 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2762 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2763 theDI << aName.ToCString() << " ";
2764 if (!anIO.IsNull())
2765 {
a272ed94 2766 if (toEraseInView)
2767 {
2768 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2769 }
2770 else
2771 {
2772 aCtx->Erase (anIO, Standard_False);
2773 }
b514beda 2774 }
7fd59977 2775 }
7fd59977 2776 }
c3282ec1 2777 else if (!toEraseAll && aCtx->NbSelected() > 0)
b514beda 2778 {
b6d587e3 2779 // Erase selected objects
671b6fe0 2780 const Standard_Boolean aHasOpenedContext = aCtx->HasOpenedContext();
b514beda 2781 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2782 anIter.More(); anIter.Next())
2783 {
2784 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2785 if (!anIO.IsNull()
c3282ec1 2786 && aCtx->IsSelected (anIO))
b514beda 2787 {
2788 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2789 if (toEraseInView)
2790 {
2791 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2792 }
671b6fe0 2793 else if (aHasOpenedContext)
a272ed94 2794 {
2795 aCtx->Erase (anIO, Standard_False);
2796 }
7fd59977 2797 }
2798 }
671b6fe0 2799
2800 if (!toEraseInView)
2801 {
2802 aCtx->EraseSelected (Standard_False);
2803 }
b514beda 2804 }
519d35d8 2805 else
b514beda 2806 {
b6d587e3 2807 // Erase all objects
519d35d8 2808 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2809 anIter.More(); anIter.Next())
b514beda 2810 {
519d35d8 2811 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2812 if (!anIO.IsNull())
2813 {
a272ed94 2814 if (toEraseInView)
2815 {
2816 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2817 }
2818 else
2819 {
2820 aCtx->Erase (anIO, Standard_False);
2821 }
519d35d8 2822 }
7fd59977 2823 }
7fd59977 2824 }
b6d587e3 2825
7fd59977 2826 return 0;
2827}
2828
7fd59977 2829//==============================================================================
2830//function : VDisplayAll
2831//author : ege
2832//purpose : Display all the objects of the Map
7fd59977 2833//==============================================================================
519d35d8 2834static int VDisplayAll (Draw_Interpretor& ,
2835 Standard_Integer theArgNb,
2836 const char** theArgVec)
7fd59977 2837
2838{
4e18052b 2839 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2840 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2841 if (aCtx.IsNull())
519d35d8 2842 {
b6d587e3 2843 std::cerr << "Error: no active view!\n";
519d35d8 2844 return 1;
2845 }
2846
519d35d8 2847 Standard_Integer anArgIter = 1;
b6d587e3 2848 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2849 for (; anArgIter < theArgNb; ++anArgIter)
2850 {
b6d587e3 2851 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2852 anArgCase.LowerCase();
2853 if (anArgCase == "-local")
2854 {
2855 toDisplayLocal = Standard_True;
2856 }
2857 else if (anUpdateTool.parseRedrawMode (anArgCase))
2858 {
2859 continue;
2860 }
2861 else
519d35d8 2862 {
2863 break;
7fd59977 2864 }
519d35d8 2865 }
2866 if (anArgIter < theArgNb)
2867 {
2868 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2869 return 1;
2870 }
2871
b6d587e3 2872 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2873 {
b6d587e3 2874 std::cerr << "Error: local selection context is not open.\n";
2875 return 1;
2876 }
2877 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2878 {
2879 aCtx->CloseLocalContext (Standard_False);
519d35d8 2880 }
2881
2882 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2883 anIter.More(); anIter.Next())
2884 {
d09dda09 2885 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2886 aCtx->Erase (aShape, Standard_False);
519d35d8 2887 }
2888
2889 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2890 anIter.More(); anIter.Next())
2891 {
d09dda09 2892 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2893 aCtx->Display (aShape, Standard_False);
7fd59977 2894 }
2895 return 0;
2896}
2897
c2a388f8 2898//! Auxiliary method to find presentation
2899inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2900 const Handle(AIS_InteractiveObject)& theIO,
2901 const Standard_Integer theMode)
2902{
2903 if (theIO.IsNull())
2904 {
2905 return Handle(PrsMgr_Presentation)();
2906 }
2907
2908 if (theMode != -1)
2909 {
2910 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2911 {
2912 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2913 }
2914 }
2915 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2916 {
2917 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2918 }
2919 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2920 {
2921 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2922 }
2923 return Handle(PrsMgr_Presentation)();
2924}
2925
2926enum ViewerTest_BndAction
2927{
2928 BndAction_Hide,
2929 BndAction_Show,
2930 BndAction_Print
2931};
2932
2933//! Auxiliary method to print bounding box of presentation
2934inline void bndPresentation (Draw_Interpretor& theDI,
2935 const Handle(PrsMgr_Presentation)& thePrs,
2936 const TCollection_AsciiString& theName,
2937 const ViewerTest_BndAction theAction)
2938{
2939 switch (theAction)
2940 {
2941 case BndAction_Hide:
2942 {
2943 thePrs->Presentation()->GraphicUnHighlight();
2944 break;
2945 }
2946 case BndAction_Show:
2947 {
5b111128 2948 Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
a1954302 2949 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2950 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2951 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2952 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
c2a388f8 2953 break;
2954 }
2955 case BndAction_Print:
2956 {
ed063270 2957 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2958 gp_Pnt aMin = aBox.CornerMin();
2959 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 2960 theDI << theName << "\n"
ed063270 2961 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2962 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 2963 break;
2964 }
2965 }
2966}
2967
2968//==============================================================================
2969//function : VBounding
2970//purpose :
2971//==============================================================================
2972int VBounding (Draw_Interpretor& theDI,
2973 Standard_Integer theArgNb,
2974 const char** theArgVec)
2975{
2976 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2977 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2978 if (aCtx.IsNull())
2979 {
2980 std::cout << "Error: no active view!\n";
2981 return 1;
2982 }
2983
4e18052b 2984 ViewerTest_BndAction anAction = BndAction_Show;
2985 Standard_Integer aMode = -1;
c2a388f8 2986
2987 Standard_Integer anArgIter = 1;
2988 for (; anArgIter < theArgNb; ++anArgIter)
2989 {
2990 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2991 anArg.LowerCase();
2992 if (anArg == "-print")
2993 {
2994 anAction = BndAction_Print;
2995 }
2996 else if (anArg == "-show")
2997 {
2998 anAction = BndAction_Show;
2999 }
3000 else if (anArg == "-hide")
3001 {
3002 anAction = BndAction_Hide;
3003 }
3004 else if (anArg == "-mode")
3005 {
3006 if (++anArgIter >= theArgNb)
3007 {
3008 std::cout << "Error: wrong syntax at " << anArg << "\n";
3009 return 1;
3010 }
3011 aMode = Draw::Atoi (theArgVec[anArgIter]);
3012 }
4e18052b 3013 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 3014 {
3015 break;
3016 }
3017 }
3018
3019 if (anArgIter < theArgNb)
3020 {
3021 // has a list of names
3022 for (; anArgIter < theArgNb; ++anArgIter)
3023 {
3024 TCollection_AsciiString aName = theArgVec[anArgIter];
3025 if (!GetMapOfAIS().IsBound2 (aName))
3026 {
3027 std::cout << "Error: presentation " << aName << " does not exist\n";
3028 return 1;
3029 }
3030
3031 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3032 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3033 if (aPrs.IsNull())
3034 {
3035 std::cout << "Error: presentation " << aName << " does not exist\n";
3036 return 1;
3037 }
3038 bndPresentation (theDI, aPrs, aName, anAction);
3039 }
3040 }
c3282ec1 3041 else if (aCtx->NbSelected() > 0)
c2a388f8 3042 {
3043 // remove all currently selected objects
c3282ec1 3044 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
c2a388f8 3045 {
c3282ec1 3046 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
c2a388f8 3047 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3048 if (!aPrs.IsNull())
3049 {
3050 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
3051 }
3052 }
3053 }
3054 else
3055 {
3056 // all objects
3057 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3058 anIter.More(); anIter.Next())
3059 {
3060 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3061 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3062 if (!aPrs.IsNull())
3063 {
3064 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
3065 }
3066 }
3067 }
c2a388f8 3068 return 0;
3069}
3070
d399d3c3 3071//==============================================================================
3072//function : VTexture
3073//purpose :
3074//==============================================================================
3075Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 3076{
d399d3c3 3077 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 3078
900f7229 3079 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 3080 if (aCommandName == "vtexture")
3081 {
3082 if (theArgsNb < 2)
7fd59977 3083 {
586db386 3084 std::cout << theArgv[0] << ": invalid arguments.\n";
d399d3c3 3085 std::cout << "Type help for more information.\n";
31160f80 3086 return 1;
7fd59977 3087 }
3088
d399d3c3 3089 // look for options of vtexture command
3090 TCollection_AsciiString aParseKey;
3091 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3092 {
3093 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 3094
d399d3c3 3095 anArg.UpperCase();
3096 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3097 {
3098 aParseKey = anArg;
3099 aParseKey.Remove (1);
3100 aParseKey.UpperCase();
900f7229 3101 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 3102 continue;
3103 }
3104
3105 if (aParseKey.IsEmpty())
3106 {
3107 continue;
3108 }
3109
900f7229 3110 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 3111 }
3112 }
3113 else if (aCommandName == "vtexscale"
3114 || aCommandName == "vtexorigin"
3115 || aCommandName == "vtexrepeat")
3116 {
3117 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3118 // equal to -scale, -origin, -repeat options of vtexture command
3119 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 3120 {
586db386 3121 std::cout << theArgv[0] << ": invalid arguments.\n";
d399d3c3 3122 std::cout << "Type help for more information.\n";
31160f80 3123 return 1;
7fd59977 3124 }
3125
900f7229 3126 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 3127 if (theArgsNb == 2)
3128 {
900f7229 3129 anArgs->Append ("OFF");
d399d3c3 3130 }
3131 else if (theArgsNb == 4)
3132 {
900f7229 3133 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3134 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 3135 }
7fd59977 3136
d399d3c3 3137 TCollection_AsciiString anArgKey;
3138 if (aCommandName == "vtexscale")
3139 {
3140 anArgKey = "SCALE";
3141 }
3142 else if (aCommandName == "vtexorigin")
3143 {
3144 anArgKey = "ORIGIN";
3145 }
3146 else
3147 {
3148 anArgKey = "REPEAT";
3149 }
3150
3151 aMapOfArgs.Bind (anArgKey, anArgs);
3152 }
3153 else if (aCommandName == "vtexdefault")
7fd59977 3154 {
d399d3c3 3155 // scan for parameters of vtexdefault command
3156 // equal to -default option of vtexture command
900f7229 3157 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 3158 }
3159
d399d3c3 3160 // Check arguments for validity
900f7229 3161 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 3162 for (; aMapIt.More(); aMapIt.Next())
3163 {
3164 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 3165 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 3166
3167 // -scale, -origin, -repeat: one argument "off", or two real values
3168 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 3169 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3170 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 3171 {
d399d3c3 3172 continue;
7fd59977 3173 }
d399d3c3 3174
3175 // -modulate: single argument "on" / "off"
900f7229 3176 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 3177 {
3178 continue;
3179 }
3180
3181 // -default: no arguments
900f7229 3182 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 3183 {
3184 continue;
3185 }
3186
3187 TCollection_AsciiString aLowerKey;
3188 aLowerKey = "-";
3189 aLowerKey += aKey;
3190 aLowerKey.LowerCase();
3191 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3192 std::cout << "Type help for more information.\n";
3193 return 1;
3194 }
3195
3196 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3197 if (anAISContext.IsNull())
3198 {
586db386 3199 std::cout << aCommandName << ": please use 'vinit' command to initialize view.\n";
d399d3c3 3200 return 1;
3201 }
3202
3203 Standard_Integer aPreviousMode = 0;
3204
d399d3c3 3205 TCollection_AsciiString aShapeName (theArgv[1]);
3206 Handle(AIS_InteractiveObject) anIO;
3207
3208 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3209 if (aMapOfIO.IsBound2 (aShapeName))
3210 {
3211 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3212 }
3213
3214 if (anIO.IsNull())
3215 {
3216 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3217 return 1;
3218 }
3219
3220 Handle(AIS_TexturedShape) aTexturedIO;
3221 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3222 {
3223 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3224 aPreviousMode = aTexturedIO->DisplayMode();
3225 }
7fd59977 3226 else
d399d3c3 3227 {
d399d3c3 3228 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
16420da1 3229
3230 if (anIO->HasTransformation())
3231 {
3232 const gp_Trsf& aLocalTrsf = anIO->LocalTransformation();
3233 aTexturedIO->SetLocalTransformation (aLocalTrsf);
3234 }
3235
3236 anAISContext->Remove (anIO, Standard_False);
d399d3c3 3237 GetMapOfAIS().UnBind1 (anIO);
3238 GetMapOfAIS().UnBind2 (aShapeName);
3239 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3240 }
3241
3242 // -------------------------------------------
3243 // Turn texturing on/off - only for vtexture
3244 // -------------------------------------------
3245
3246 if (aCommandName == "vtexture")
3247 {
3248 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3249
3250 if (aTextureArg.IsEmpty())
7fd59977 3251 {
586db386 3252 std::cout << aCommandName << ": Texture mapping disabled.\n";
3253 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n\n";
d399d3c3 3254
3255 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3256 if (aPreviousMode == 3)
3257 {
3258 anAISContext->RecomputePrsOnly (aTexturedIO);
3259 }
3260
3261 anAISContext->Display (aTexturedIO, Standard_True);
3262 return 0;
7fd59977 3263 }
d399d3c3 3264 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3265 {
d399d3c3 3266 if (aTextureArg == "?")
3267 {
3268 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3269
586db386 3270 theDi << "\n Files in current directory : \n\n";
d399d3c3 3271 theDi.Eval ("glob -nocomplain *");
7fd59977 3272
d399d3c3 3273 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3274 aCmnd += aTextureFolder;
3275 aCmnd += "/* ";
7fd59977 3276
586db386 3277 theDi << "Files in " << aTextureFolder.ToCString() << " : \n\n";
d399d3c3 3278 theDi.Eval (aCmnd.ToCString());
3279 return 0;
3280 }
3281 else
3282 {
3283 aTexturedIO->SetTextureFileName (aTextureArg);
3284 }
3285 }
3286 }
7fd59977 3287
d399d3c3 3288 // ------------------------------------
3289 // Process other options and commands
3290 // ------------------------------------
7fd59977 3291
900f7229 3292 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3293 if (aMapOfArgs.Find ("DEFAULT", aValues))
3294 {
3295 aTexturedIO->SetTextureRepeat (Standard_False);
3296 aTexturedIO->SetTextureOrigin (Standard_False);
3297 aTexturedIO->SetTextureScale (Standard_False);
3298 aTexturedIO->EnableTextureModulate();
3299 }
3300 else
3301 {
3302 if (aMapOfArgs.Find ("SCALE", aValues))
3303 {
900f7229 3304 if (aValues->Value(1) != "OFF")
d399d3c3 3305 {
900f7229 3306 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3307 }
7fd59977 3308 else
d399d3c3 3309 {
3310 aTexturedIO->SetTextureScale (Standard_False);
3311 }
3312 }
7fd59977 3313
d399d3c3 3314 if (aMapOfArgs.Find ("ORIGIN", aValues))
3315 {
900f7229 3316 if (aValues->Value(1) != "OFF")
d399d3c3 3317 {
900f7229 3318 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3319 }
3320 else
3321 {
3322 aTexturedIO->SetTextureOrigin (Standard_False);
3323 }
3324 }
7fd59977 3325
d399d3c3 3326 if (aMapOfArgs.Find ("REPEAT", aValues))
3327 {
900f7229 3328 if (aValues->Value(1) != "OFF")
d399d3c3 3329 {
900f7229 3330 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3331 }
3332 else
3333 {
3334 aTexturedIO->SetTextureRepeat (Standard_False);
3335 }
7fd59977 3336 }
3337
d399d3c3 3338 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 3339 {
900f7229 3340 if (aValues->Value(1) == "ON")
d399d3c3 3341 {
3342 aTexturedIO->EnableTextureModulate();
3343 }
3344 else
3345 {
3346 aTexturedIO->DisableTextureModulate();
3347 }
7fd59977 3348 }
d399d3c3 3349 }
3350
3351 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3352 {
3353 anAISContext->RecomputePrsOnly (aTexturedIO);
3354 }
3355 else
3356 {
3357 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3358 anAISContext->Display (aTexturedIO, Standard_True);
3359 anAISContext->Update (aTexturedIO,Standard_True);
3360 }
3361
31160f80 3362 return 0;
7fd59977 3363}
3364
af65fb19 3365//! Auxiliary method to parse transformation persistence flags
3366inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3367 Standard_Integer& theFlags)
3368{
3369 if (theFlagString == "pan")
3370 {
3371 theFlags |= Graphic3d_TMF_PanPers;
3372 }
3373 else if (theFlagString == "zoom")
3374 {
3375 theFlags |= Graphic3d_TMF_ZoomPers;
3376 }
3377 else if (theFlagString == "rotate")
3378 {
3379 theFlags |= Graphic3d_TMF_RotatePers;
3380 }
3381 else if (theFlagString == "trihedron")
3382 {
3383 theFlags = Graphic3d_TMF_TriedronPers;
3384 }
3385 else if (theFlagString == "full")
3386 {
3387 theFlags = Graphic3d_TMF_FullPers;
3388 }
3389 else if (theFlagString == "none")
3390 {
3391 theFlags = Graphic3d_TMF_None;
3392 }
3393 else
3394 {
3395 return Standard_False;
3396 }
3397
3398 return Standard_True;
3399}
3400
7fd59977 3401//==============================================================================
3402//function : VDisplay2
3403//author : ege
3404//purpose : Display an object from its name
7fd59977 3405//==============================================================================
519d35d8 3406static int VDisplay2 (Draw_Interpretor& theDI,
3407 Standard_Integer theArgNb,
3408 const char** theArgVec)
7fd59977 3409{
519d35d8 3410 if (theArgNb < 2)
3411 {
b6d587e3 3412 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 3413 return 1;
3414 }
b6d587e3 3415
3416 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3417 if (aCtx.IsNull())
519d35d8 3418 {
7fd59977 3419 ViewerTest::ViewerInit();
4e18052b 3420 aCtx = ViewerTest::GetAISContext();
7fd59977 3421 }
3422
b6d587e3 3423 // Parse input arguments
4e18052b 3424 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 3425 Standard_Integer isMutable = -1;
3426 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3427 Standard_Boolean toDisplayLocal = Standard_False;
3428 Standard_Boolean toReDisplay = Standard_False;
af65fb19 3429 Standard_Integer isSelectable = -1;
3430 Standard_Integer anObjDispMode = -2;
3431 Standard_Integer anObjHighMode = -2;
3432 Standard_Boolean toSetTrsfPers = Standard_False;
3433 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3434 gp_Pnt aTPPosition;
b6d587e3 3435 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 3436 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94 3437 Standard_Integer toDisplayInView = Standard_False;
519d35d8 3438 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3439 {
b7cd4ba7 3440 const TCollection_AsciiString aName = theArgVec[anArgIter];
3441 TCollection_AsciiString aNameCase = aName;