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