0026273: Comments to methods are misplaced in gp_Vec.cdl
[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
108//=======================================================================
536d98e2 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
158//=======================================================================
7fd59977 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();
390 EM = *((Handle(ViewerTest_EventManager)*)&Tr);
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){
443 retsh = *((Handle(AIS_Shape)*)&IO);
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
499 aContext->UnhilightCurrents(Standard_False);
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
502 if (!aContext->FirstCurrentObject().IsNull()){
503 aContext->OpenLocalContext(Standard_False);
504
505 for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){
506 aContext->Load( aContext->Current(),-1,Standard_True);
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
542//==============================================================================
1c88cbaf 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
721//==============================================================================
3c982548 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
762//==============================================================================
7fd59977 763//function : VDump
764//purpose : To dump the active view snapshot to image file
7fd59977 765//==============================================================================
34db9c00 766static Standard_Integer VDump (Draw_Interpretor& theDI,
767 Standard_Integer theArgNb,
768 Standard_CString* theArgVec)
7fd59977 769{
34db9c00 770 if (theArgNb < 2)
7fd59977 771 {
34db9c00 772 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
7fd59977 773 return 1;
774 }
775
34db9c00 776 Standard_Integer anArgIter = 1;
777 Standard_CString aFilePath = theArgVec[anArgIter++];
778 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
779 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
780 Standard_Integer aWidth = 0;
781 Standard_Integer aHeight = 0;
782 for (; anArgIter < theArgNb; ++anArgIter)
7fd59977 783 {
34db9c00 784 TCollection_AsciiString anArg (theArgVec[anArgIter]);
785 anArg.LowerCase();
786 if (anArg == "rgba")
7fd59977 787 {
34db9c00 788 aBufferType = Graphic3d_BT_RGBA;
7fd59977 789 }
34db9c00 790 else if (anArg == "rgb")
7fd59977 791 {
34db9c00 792 aBufferType = Graphic3d_BT_RGB;
7fd59977 793 }
34db9c00 794 else if (anArg == "depth")
7fd59977 795 {
692613e5 796 aBufferType = Graphic3d_BT_Depth;
7fd59977 797 }
34db9c00 798 else if (anArg == "l"
799 || anArg == "left")
800 {
801 aStereoOpts = V3d_SDO_LEFT_EYE;
802 }
803 else if (anArg == "r"
804 || anArg == "right")
805 {
806 aStereoOpts = V3d_SDO_RIGHT_EYE;
807 }
808 else if (anArg == "mono")
809 {
810 aStereoOpts = V3d_SDO_MONO;
811 }
812 else if (anArg == "w"
813 || anArg == "width")
814 {
815 if (aWidth != 0)
816 {
817 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
818 return 1;
819 }
820 else if (++anArgIter >= theArgNb)
821 {
822 std::cout << "Error: integer value is expected right after 'width'\n";
823 return 1;
824 }
825 aWidth = Draw::Atoi (theArgVec[anArgIter]);
826 }
827 else if (anArg == "h"
828 || anArg == "height")
829 {
830 if (aHeight != 0)
831 {
832 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
833 return 1;
834 }
835 if (++anArgIter >= theArgNb)
836 {
837 std::cout << "Error: integer value is expected right after 'height'\n";
838 return 1;
839 }
840 aHeight = Draw::Atoi (theArgVec[anArgIter]);
841 }
842 else if (anArg.IsIntegerValue())
843 {
844 // compatibility with old syntax
845 if (aWidth != 0
846 || aHeight != 0)
847 {
848 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
849 return 1;
850 }
851 else if (++anArgIter >= theArgNb)
852 {
853 std::cout << "Error: height value is expected right after width\n";
854 return 1;
855 }
856 aWidth = Draw::Atoi (theArgVec[anArgIter - 1]);
857 aHeight = Draw::Atoi (theArgVec[anArgIter]);
858 }
859 else
860 {
861 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
862 return 1;
863 }
7fd59977 864 }
34db9c00 865 if ((aWidth <= 0 && aHeight > 0)
866 || (aWidth > 0 && aHeight <= 0))
7fd59977 867 {
34db9c00 868 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
85e096c3 869 return 1;
870 }
871
34db9c00 872 Handle(V3d_View) aView = ViewerTest::CurrentView();
873 if (aView.IsNull())
85e096c3 874 {
34db9c00 875 std::cout << "Error: cannot find an active view!\n";
876 return 1;
7fd59977 877 }
85e096c3 878
34db9c00 879 if (aWidth <= 0 || aHeight <= 0)
b5ac8292 880 {
34db9c00 881 if (aStereoOpts != V3d_SDO_MONO)
b5ac8292 882 {
34db9c00 883 aView->Window()->Size (aWidth, aHeight);
b5ac8292 884 }
34db9c00 885 else
b5ac8292 886 {
34db9c00 887 if (!aView->Dump (aFilePath, aBufferType))
888 {
889 theDI << "Fail: view dump failed!\n";
890 }
891 return 0;
b5ac8292 892 }
893 }
894
692613e5 895 Image_AlienPixMap aPixMap;
34db9c00 896 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
7fd59977 897 {
34db9c00 898 theDI << "Fail: view dump failed!\n";
899 return 0;
7fd59977 900 }
85e096c3 901
692613e5 902 if (aPixMap.SizeX() != Standard_Size(aWidth)
903 || aPixMap.SizeY() != Standard_Size(aHeight))
85e096c3 904 {
34db9c00 905 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
906 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
85e096c3 907 }
34db9c00 908 if (!aPixMap.Save (aFilePath))
85e096c3 909 {
34db9c00 910 theDI << "Fail: image can not be saved!\n";
85e096c3 911 }
912 return 0;
7fd59977 913}
914
915
916//==============================================================================
917//function : Displays,Erase...
918//purpose :
919//Draw arg :
920//==============================================================================
921static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
922 const Standard_Integer Mode,
923 const Standard_Integer TypeOfOperation,
924 const Standard_Boolean Upd)
925{
926 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
927
928 switch(TypeOfOperation){
929 case 1:
930 Ctx->Display(IO,Mode,Upd);
931 break;
932 case 2:{
eb4320f2 933 Ctx->Erase(IO,Upd);
7fd59977 934 break;
935 }
936 case 3:{
937 if(IO.IsNull())
938 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
939 else
940 Ctx->SetDisplayMode(IO,Mode,Upd);
941 break;
942 }
943 case 4:{
944 if(IO.IsNull())
945 Ctx->SetDisplayMode(0,Upd);
946 else
947 Ctx->UnsetDisplayMode(IO,Upd);
948 break;
949 }
950 }
951 return 0;
952}
953
954//=======================================================================
955//function :
956//purpose :
957//=======================================================================
958static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
959{
960
961 TCollection_AsciiString name;
962 if(argc>3)
963 return 1;
964 // display others presentations
965 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
966 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
967 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
968 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
969
970 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
971
972 //unset displaymode.. comportement particulier...
973 if(TypeOfOperation==4){
974 if(argc==1){
975 if(Ctx->NbCurrents()==0 ||
976 Ctx->NbSelected()==0){
977 Handle(AIS_InteractiveObject) IO;
978 VwrTst_DispErase(IO,-1,4,Standard_False);
979 }
980 else if(!Ctx->HasOpenedContext()){
981 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent())
982 VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False);
983 }
984 else{
985 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
986 VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);}
987 Ctx->UpdateCurrentViewer();
988 }
989 else{
990 Handle(AIS_InteractiveObject) IO;
991 name = argv[1];
992 if(GetMapOfAIS().IsBound2(name)){
993 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
994 if (!IO.IsNull())
995 VwrTst_DispErase(IO,-1,4,Standard_True);
996 }
997 }
998 }
999 else if(argc==2){
91322f44 1000 Standard_Integer Dmode = Draw::Atoi(argv[1]);
7fd59977 1001 if(Ctx->NbCurrents()==0 && TypeOfOperation==3){
1002 Handle(AIS_InteractiveObject) IO;
1003 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1004 }
1005 if(!Ctx->HasOpenedContext()){
1006 // set/unset display mode sur le Contexte...
1007 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1008 VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False);
1009 }
1010 Ctx->UpdateCurrentViewer();
1011 }
1012 else{
1013 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
1014 Ctx->Display(Ctx->Interactive(),Dmode);
1015 }
1016 }
1017 else{
1018 Handle(AIS_InteractiveObject) IO;
1019 name = argv[1];
1020 if(GetMapOfAIS().IsBound2(name))
1021 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1022 if (!IO.IsNull())
91322f44 1023 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
7fd59977 1024 }
1025 return 0;
1026}
1027
1028
1029//=======================================================================
1030//function :
1031//purpose :
1032//=======================================================================
1033static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1034{
1035 if(argc==1) return 1;
91322f44 1036 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 1037 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1038
1039 if(argc==2){
1040
1041 if(!Ctx->HasOpenedContext()){
1042 di<<"sub intensite ";
1043 if(On==1) di<<"On";
1044 else di<<"Off";
1045 di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n";
1046 for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){
1047 if(On==1){
1048 Ctx->SubIntensityOn(Ctx->Current(),Standard_False);}
1049 else{
1050 di <<"passage dans off"<<"\n";
1051 Ctx->SubIntensityOff(Ctx->Current(),Standard_False);
1052 }
1053 }
1054 }
1055 else{
1056 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1057 if(On==1){
1058 Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);}
1059 else{
1060 Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);}
1061 }
1062 }
1063 Ctx->UpdateCurrentViewer();
1064 }
1065 else {
1066 Handle(AIS_InteractiveObject) IO;
1067 TCollection_AsciiString name = argv[2];
1068 if(GetMapOfAIS().IsBound2(name)){
1069 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
eafb234b 1070 if (!IO.IsNull()) {
7fd59977 1071 if(On==1)
1072 Ctx->SubIntensityOn(IO);
1073 else
1074 Ctx->SubIntensityOff(IO);
eafb234b 1075 }
7fd59977 1076 }
1077 else return 1;
1078 }
1079 return 0;
7fd59977 1080}
7fd59977 1081
ad3217cd 1082//! Auxiliary class to iterate presentations from different collections.
1083class ViewTest_PrsIter
1084{
1085public:
7fd59977 1086
ad3217cd 1087 //! Create and initialize iterator object.
1088 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1089 : mySource (IterSource_All)
1090 {
1091 NCollection_Sequence<TCollection_AsciiString> aNames;
1092 if (!theName.IsEmpty())
1093 aNames.Append (theName);
1094 Init (aNames);
7fd59977 1095 }
ad3217cd 1096
1097 //! Create and initialize iterator object.
1098 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1099 : mySource (IterSource_All)
1100 {
1101 Init (theNames);
7fd59977 1102 }
1103
ad3217cd 1104 //! Initialize the iterator.
1105 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1106 {
1107 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1108 mySeq = theNames;
1109 mySelIter.Nullify();
1110 myCurrent.Nullify();
1111 myCurrentTrs.Nullify();
1112 if (!mySeq.IsEmpty())
1113 {
1114 mySource = IterSource_List;
1115 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
7fd59977 1116 }
ad3217cd 1117 else if (aCtx->NbCurrents() > 0)
1118 {
1119 mySource = IterSource_Selected;
1120 mySelIter = aCtx;
1121 mySelIter->InitCurrent();
1122 }
1123 else
1124 {
1125 mySource = IterSource_All;
1126 myMapIter.Initialize (GetMapOfAIS());
1127 }
1128 initCurrent();
1129 }
7fd59977 1130
ad3217cd 1131 const TCollection_AsciiString& CurrentName() const
1132 {
1133 return myCurrentName;
1134 }
7fd59977 1135
ad3217cd 1136 const Handle(AIS_InteractiveObject)& Current() const
1137 {
1138 return myCurrent;
1139 }
7fd59977 1140
ad3217cd 1141 const Handle(Standard_Transient)& CurrentTrs() const
1142 {
1143 return myCurrentTrs;
1144 }
1145
1146 //! @return true if iterator points to valid object within collection
1147 Standard_Boolean More() const
1148 {
1149 switch (mySource)
1150 {
1151 case IterSource_All: return myMapIter.More();
1152 case IterSource_List: return mySeqIter.More();
1153 case IterSource_Selected: return mySelIter->MoreCurrent();
1154 }
1155 return Standard_False;
1156 }
1157
1158 //! Go to the next item.
1159 void Next()
1160 {
1161 myCurrentName.Clear();
1162 myCurrentTrs.Nullify();
1163 myCurrent.Nullify();
1164 switch (mySource)
1165 {
1166 case IterSource_All:
1167 {
1168 myMapIter.Next();
1169 break;
1170 }
1171 case IterSource_List:
1172 {
1173 mySeqIter.Next();
1174 break;
1175 }
1176 case IterSource_Selected:
1177 {
1178 mySelIter->NextCurrent();
1179 break;
7fd59977 1180 }
1181 }
ad3217cd 1182 initCurrent();
1183 }
7fd59977 1184
ad3217cd 1185private:
7fd59977 1186
ad3217cd 1187 void initCurrent()
1188 {
1189 switch (mySource)
1190 {
1191 case IterSource_All:
7fd59977 1192 {
ad3217cd 1193 if (myMapIter.More())
1194 {
1195 myCurrentName = myMapIter.Key2();
1196 myCurrentTrs = myMapIter.Key1();
1197 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
eafb234b 1198 }
ad3217cd 1199 break;
1200 }
1201 case IterSource_List:
1202 {
1203 if (mySeqIter.More())
1204 {
1205 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1206 {
1207 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1208 return;
1209 }
1210 myCurrentName = mySeqIter.Value();
1211 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1212 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1213 }
1214 break;
1215 }
1216 case IterSource_Selected:
1217 {
1218 if (mySelIter->MoreCurrent())
1219 {
1220 myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current());
1221 myCurrent = mySelIter->Current();
1222 }
1223 break;
7fd59977 1224 }
7fd59977 1225 }
1226 }
ad3217cd 1227
1228private:
1229
1230 enum IterSource
1231 {
1232 IterSource_All,
1233 IterSource_List,
1234 IterSource_Selected
1235 };
1236
1237private:
1238
1239 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1240 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1241 NCollection_Sequence<TCollection_AsciiString> mySeq;
1242 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1243
1244 TCollection_AsciiString myCurrentName;//!< current item name
1245 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1246 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1247
1248 IterSource mySource; //!< iterated collection
1249
1250};
7fd59977 1251
1252//==============================================================================
ad3217cd 1253//function : VInteriorStyle
1254//purpose : sets interior style of the a selected or named or displayed shape
7fd59977 1255//==============================================================================
ad3217cd 1256static int VSetInteriorStyle (Draw_Interpretor& theDI,
1257 Standard_Integer theArgNb,
1258 const char** theArgVec)
7fd59977 1259{
ad3217cd 1260 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1261 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1262 if (aCtx.IsNull())
1263 {
1264 std::cerr << "Error: no active view!\n";
1265 return 1;
1266 }
7fd59977 1267
4e18052b 1268 Standard_Integer anArgIter = 1;
ad3217cd 1269 for (; anArgIter < theArgNb; ++anArgIter)
1270 {
4e18052b 1271 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
ad3217cd 1272 {
1273 break;
1274 }
7fd59977 1275 }
ad3217cd 1276 TCollection_AsciiString aName;
1277 if (theArgNb - anArgIter == 2)
1278 {
1279 aName = theArgVec[anArgIter++];
1280 }
1281 else if (theArgNb - anArgIter != 1)
1282 {
1283 std::cout << "Error: wrong number of arguments! See usage:\n";
1284 theDI.PrintHelp (theArgVec[0]);
1285 return 1;
1286 }
1287 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1288 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1289 aStyleArg.LowerCase();
1290 if (aStyleArg == "empty")
1291 {
1292 anInterStyle = 0;
1293 }
1294 else if (aStyleArg == "hollow")
1295 {
1296 anInterStyle = 1;
1297 }
1298 else if (aStyleArg == "hatch")
1299 {
1300 anInterStyle = 2;
1301 }
1302 else if (aStyleArg == "solid")
1303 {
1304 anInterStyle = 3;
1305 }
1306 else if (aStyleArg == "hiddenline")
1307 {
1308 anInterStyle = 4;
1309 }
1310 else
1311 {
1312 anInterStyle = aStyleArg.IntegerValue();
1313 }
1314 if (anInterStyle < Aspect_IS_EMPTY
1315 || anInterStyle > Aspect_IS_HIDDENLINE)
1316 {
1317 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1318 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1319 return 1;
7fd59977 1320 }
1321
ad3217cd 1322 if (!aName.IsEmpty()
1323 && !GetMapOfAIS().IsBound2 (aName))
1324 {
1325 std::cout << "Error: object " << aName << " is not displayed!\n";
1326 return 1;
1327 }
1328
1329 if (aCtx->HasOpenedContext())
1330 {
1331 aCtx->CloseLocalContext();
1332 }
1333 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1334 {
1335 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1336 if (!anIO.IsNull())
1337 {
1338 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1339 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1340 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1341 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1342 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
7fd59977 1343 }
ad3217cd 1344 }
ad3217cd 1345 return 0;
1346}
7fd59977 1347
ad3217cd 1348//! Auxiliary structure for VAspects
1349struct ViewerTest_AspectsChangeSet
1350{
5bffb882 1351 Standard_Integer ToSetVisibility;
1352 Standard_Integer Visibility;
1353
ad3217cd 1354 Standard_Integer ToSetColor;
1355 Quantity_Color Color;
1356
1357 Standard_Integer ToSetLineWidth;
1358 Standard_Real LineWidth;
1359
ac116c22 1360 Standard_Integer ToSetTypeOfLine;
1361 Aspect_TypeOfLine TypeOfLine;
1362
ad3217cd 1363 Standard_Integer ToSetTransparency;
1364 Standard_Real Transparency;
1365
1366 Standard_Integer ToSetMaterial;
1367 Graphic3d_NameOfMaterial Material;
1368 TCollection_AsciiString MatName;
1369
1370 NCollection_Sequence<TopoDS_Shape> SubShapes;
1371
6262338c 1372 Standard_Integer ToSetShowFreeBoundary;
1373 Standard_Integer ToSetFreeBoundaryWidth;
1374 Standard_Real FreeBoundaryWidth;
1375 Standard_Integer ToSetFreeBoundaryColor;
1376 Quantity_Color FreeBoundaryColor;
1377
ad3217cd 1378 //! Empty constructor
1379 ViewerTest_AspectsChangeSet()
5bffb882 1380 : ToSetVisibility (0),
1381 Visibility (1),
1382 ToSetColor (0),
ad3217cd 1383 Color (DEFAULT_COLOR),
1384 ToSetLineWidth (0),
1385 LineWidth (1.0),
ac116c22 1386 ToSetTypeOfLine (0),
1387 TypeOfLine (Aspect_TOL_SOLID),
ad3217cd 1388 ToSetTransparency (0),
1389 Transparency (0.0),
1390 ToSetMaterial (0),
6262338c 1391 Material (Graphic3d_NOM_DEFAULT),
1392 ToSetShowFreeBoundary (0),
1393 ToSetFreeBoundaryWidth (0),
1394 FreeBoundaryWidth (1.0),
1395 ToSetFreeBoundaryColor (0),
1396 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR) {}
ad3217cd 1397
1398 //! @return true if no changes have been requested
1399 Standard_Boolean IsEmpty() const
1400 {
6262338c 1401 return ToSetVisibility == 0
1402 && ToSetLineWidth == 0
1403 && ToSetTransparency == 0
1404 && ToSetColor == 0
1405 && ToSetMaterial == 0
1406 && ToSetShowFreeBoundary == 0
1407 && ToSetFreeBoundaryColor == 0
1408 && ToSetFreeBoundaryWidth == 0;
ad3217cd 1409 }
1410
1411 //! @return true if properties are valid
1412 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1413 {
1414 Standard_Boolean isOk = Standard_True;
5bffb882 1415 if (Visibility != 0 && Visibility != 1)
1416 {
1417 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1418 isOk = Standard_False;
1419 }
ad3217cd 1420 if (LineWidth <= 0.0
1421 || LineWidth > 10.0)
1422 {
1423 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1424 isOk = Standard_False;
7fd59977 1425 }
ad3217cd 1426 if (Transparency < 0.0
1427 || Transparency > 1.0)
1428 {
1429 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1430 isOk = Standard_False;
1431 }
1432 if (theIsSubPart
1433 && ToSetTransparency)
1434 {
1435 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1436 isOk = Standard_False;
7fd59977 1437 }
ad3217cd 1438 if (ToSetMaterial == 1
1439 && Material == Graphic3d_NOM_DEFAULT)
1440 {
1441 std::cout << "Error: unknown material " << MatName << ".\n";
1442 isOk = Standard_False;
1443 }
6262338c 1444 if (FreeBoundaryWidth <= 0.0
1445 || FreeBoundaryWidth > 10.0)
1446 {
1447 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1448 isOk = Standard_False;
1449 }
ad3217cd 1450 return isOk;
7fd59977 1451 }
7fd59977 1452
ad3217cd 1453};
7fd59977 1454
1455//==============================================================================
ad3217cd 1456//function : VAspects
1457//purpose :
7fd59977 1458//==============================================================================
ad3217cd 1459static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1460 Standard_Integer theArgNb,
1461 const char** theArgVec)
7fd59977 1462{
ad3217cd 1463 TCollection_AsciiString aCmdName (theArgVec[0]);
1464 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1465 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1466 if (aCtx.IsNull())
1467 {
1468 std::cerr << "Error: no active view!\n";
1469 return 1;
1470 }
7fd59977 1471
4e18052b 1472 Standard_Integer anArgIter = 1;
6262338c 1473 Standard_Boolean isDefaults = Standard_False;
ad3217cd 1474 NCollection_Sequence<TCollection_AsciiString> aNames;
1475 for (; anArgIter < theArgNb; ++anArgIter)
1476 {
1477 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 1478 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 1479 {
1480 continue;
1481 }
1482 else if (!anArg.IsEmpty()
1483 && anArg.Value (1) != '-')
1484 {
1485 aNames.Append (anArg);
1486 }
1487 else
1488 {
6262338c 1489 if (anArg == "-defaults")
1490 {
1491 isDefaults = Standard_True;
1492 ++anArgIter;
1493 }
ad3217cd 1494 break;
1495 }
1496 }
1497
6262338c 1498 if (!aNames.IsEmpty() && isDefaults)
1499 {
1500 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1501 return 1;
1502 }
1503
ad3217cd 1504 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1505 aChanges.Append (ViewerTest_AspectsChangeSet());
1506 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 1507
ad3217cd 1508 // parse syntax of legacy commands
1509 if (aCmdName == "vsetwidth")
1510 {
1511 if (aNames.IsEmpty()
1512 || !aNames.Last().IsRealValue())
1513 {
1514 std::cout << "Error: not enough arguments!\n";
1515 return 1;
1516 }
1517 aChangeSet->ToSetLineWidth = 1;
1518 aChangeSet->LineWidth = aNames.Last().RealValue();
1519 aNames.Remove (aNames.Length());
7fd59977 1520 }
ad3217cd 1521 else if (aCmdName == "vunsetwidth")
1522 {
1523 aChangeSet->ToSetLineWidth = -1;
1524 }
1525 else if (aCmdName == "vsetcolor")
1526 {
1527 if (aNames.IsEmpty())
1528 {
1529 std::cout << "Error: not enough arguments!\n";
1530 return 1;
1531 }
1532 aChangeSet->ToSetColor = 1;
8316c618 1533
1534 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1535 Standard_Boolean isOk = Standard_False;
1536 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1537 {
1538 aChangeSet->Color = aColor;
1539 aNames.Remove (aNames.Length());
1540 isOk = Standard_True;
1541 }
1542 else if (aNames.Length() >= 3)
1543 {
1544 const TCollection_AsciiString anRgbStr[3] =
1545 {
1546 aNames.Value (aNames.Upper() - 2),
1547 aNames.Value (aNames.Upper() - 1),
1548 aNames.Value (aNames.Upper() - 0)
1549 };
1550 isOk = anRgbStr[0].IsRealValue()
1551 && anRgbStr[1].IsRealValue()
1552 && anRgbStr[2].IsRealValue();
1553 if (isOk)
1554 {
1555 Graphic3d_Vec4d anRgb;
1556 anRgb.x() = anRgbStr[0].RealValue();
1557 anRgb.y() = anRgbStr[1].RealValue();
1558 anRgb.z() = anRgbStr[2].RealValue();
1559 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1560 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1561 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1562 {
1563 std::cout << "Error: RGB color values should be within range 0..1!\n";
1564 return 1;
1565 }
1566 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1567 aNames.Remove (aNames.Length());
1568 aNames.Remove (aNames.Length());
1569 aNames.Remove (aNames.Length());
1570 }
1571 }
1572 if (!isOk)
1573 {
1574 std::cout << "Error: not enough arguments!\n";
1575 return 1;
1576 }
ad3217cd 1577 }
1578 else if (aCmdName == "vunsetcolor")
1579 {
1580 aChangeSet->ToSetColor = -1;
1581 }
1582 else if (aCmdName == "vsettransparency")
1583 {
1584 if (aNames.IsEmpty()
1585 || !aNames.Last().IsRealValue())
1586 {
1587 std::cout << "Error: not enough arguments!\n";
1588 return 1;
1589 }
1590 aChangeSet->ToSetTransparency = 1;
1591 aChangeSet->Transparency = aNames.Last().RealValue();
1592 aNames.Remove (aNames.Length());
1593 }
1594 else if (aCmdName == "vunsettransparency")
1595 {
1596 aChangeSet->ToSetTransparency = -1;
1597 }
1598 else if (aCmdName == "vsetmaterial")
1599 {
1600 if (aNames.IsEmpty())
1601 {
1602 std::cout << "Error: not enough arguments!\n";
1603 return 1;
1604 }
1605 aChangeSet->ToSetMaterial = 1;
1606 aChangeSet->MatName = aNames.Last();
1607 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1608 aNames.Remove (aNames.Length());
1609 }
1610 else if (aCmdName == "vunsetmaterial")
1611 {
1612 aChangeSet->ToSetMaterial = -1;
1613 }
1614 else if (anArgIter >= theArgNb)
1615 {
1616 std::cout << "Error: not enough arguments!\n";
1617 return 1;
7fd59977 1618 }
1619
ad3217cd 1620 if (!aChangeSet->IsEmpty())
1621 {
1622 anArgIter = theArgNb;
1623 }
1624 for (; anArgIter < theArgNb; ++anArgIter)
1625 {
1626 TCollection_AsciiString anArg = theArgVec[anArgIter];
1627 anArg.LowerCase();
1628 if (anArg == "-setwidth"
1629 || anArg == "-setlinewidth")
1630 {
1631 if (++anArgIter >= theArgNb)
1632 {
1633 std::cout << "Error: wrong syntax at " << anArg << "\n";
1634 return 1;
1635 }
1636 aChangeSet->ToSetLineWidth = 1;
1637 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1638 }
ad3217cd 1639 else if (anArg == "-unsetwidth"
1640 || anArg == "-unsetlinewidth")
1641 {
1642 aChangeSet->ToSetLineWidth = -1;
1643 aChangeSet->LineWidth = 1.0;
1644 }
1645 else if (anArg == "-settransp"
0ae61cf3 1646 || anArg == "-settransparency")
ad3217cd 1647 {
1648 if (++anArgIter >= theArgNb)
1649 {
1650 std::cout << "Error: wrong syntax at " << anArg << "\n";
1651 return 1;
1652 }
1653 aChangeSet->ToSetTransparency = 1;
1654 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1655 if (aChangeSet->Transparency >= 0.0
1656 && aChangeSet->Transparency <= Precision::Confusion())
1657 {
1658 aChangeSet->ToSetTransparency = -1;
1659 aChangeSet->Transparency = 0.0;
eafb234b 1660 }
7fd59977 1661 }
5bffb882 1662 else if (anArg == "-setvis"
1663 || anArg == "-setvisibility")
1664 {
1665 if (++anArgIter >= theArgNb)
1666 {
1667 std::cout << "Error: wrong syntax at " << anArg << "\n";
1668 return 1;
1669 }
1670
1671 aChangeSet->ToSetVisibility = 1;
1672 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1673 }
ad3217cd 1674 else if (anArg == "-setalpha")
1675 {
1676 if (++anArgIter >= theArgNb)
7fd59977 1677 {
ad3217cd 1678 std::cout << "Error: wrong syntax at " << anArg << "\n";
1679 return 1;
1680 }
1681 aChangeSet->ToSetTransparency = 1;
1682 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1683 if (aChangeSet->Transparency < 0.0
1684 || aChangeSet->Transparency > 1.0)
1685 {
1686 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1687 return 1;
1688 }
1689 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1690 if (aChangeSet->Transparency >= 0.0
1691 && aChangeSet->Transparency <= Precision::Confusion())
1692 {
1693 aChangeSet->ToSetTransparency = -1;
1694 aChangeSet->Transparency = 0.0;
7fd59977 1695 }
7fd59977 1696 }
ad3217cd 1697 else if (anArg == "-unsettransp"
0ae61cf3 1698 || anArg == "-unsettransparency"
ad3217cd 1699 || anArg == "-unsetalpha"
1700 || anArg == "-opaque")
1701 {
1702 aChangeSet->ToSetTransparency = -1;
1703 aChangeSet->Transparency = 0.0;
1704 }
1705 else if (anArg == "-setcolor")
1706 {
8316c618 1707 Standard_Integer aNbComps = 0;
1708 Standard_Integer aCompIter = anArgIter + 1;
1709 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
ad3217cd 1710 {
8316c618 1711 if (theArgVec[aCompIter][0] == '-')
1712 {
1713 break;
1714 }
1715 }
1716 switch (aNbComps)
1717 {
1718 case 1:
1719 {
1720 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1721 Standard_CString aName = theArgVec[anArgIter + 1];
1722 if (!Quantity_Color::ColorFromName (aName, aColor))
1723 {
1724 std::cout << "Error: unknown color name '" << aName << "'\n";
1725 return 1;
1726 }
1727 aChangeSet->Color = aColor;
1728 break;
1729 }
1730 case 3:
1731 {
1732 Graphic3d_Vec3d anRgb;
1733 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1734 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1735 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1736 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1737 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1738 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1739 {
1740 std::cout << "Error: RGB color values should be within range 0..1!\n";
1741 return 1;
1742 }
1743 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1744 break;
1745 }
1746 default:
1747 {
1748 std::cout << "Error: wrong syntax at " << anArg << "\n";
1749 return 1;
1750 }
7fd59977 1751 }
ad3217cd 1752 aChangeSet->ToSetColor = 1;
8316c618 1753 anArgIter += aNbComps;
7fd59977 1754 }
ac116c22 1755 else if (anArg == "-setlinetype")
1756 {
1757 if (++anArgIter >= theArgNb)
1758 {
1759 std::cout << "Error: wrong syntax at " << anArg << "\n";
1760 return 1;
1761 }
1762
1763 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1764 aValue.LowerCase();
1765
1766 if (aValue.IsEqual ("solid"))
1767 {
1768 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1769 }
1770 else if (aValue.IsEqual ("dot"))
1771 {
1772 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1773 }
1774 else if (aValue.IsEqual ("dash"))
1775 {
1776 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1777 }
1778 else if (aValue.IsEqual ("dotdash"))
1779 {
1780 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1781 }
1782 else
1783 {
1784 std::cout << "Error: wrong syntax at " << anArg << "\n";
1785 return 1;
1786 }
1787
1788 aChangeSet->ToSetTypeOfLine = 1;
1789 }
1790 else if (anArg == "-unsetlinetype")
1791 {
1792 aChangeSet->ToSetTypeOfLine = -1;
1793 }
ad3217cd 1794 else if (anArg == "-unsetcolor")
1795 {
1796 aChangeSet->ToSetColor = -1;
1797 aChangeSet->Color = DEFAULT_COLOR;
1798 }
1799 else if (anArg == "-setmat"
1800 || anArg == "-setmaterial")
1801 {
1802 if (++anArgIter >= theArgNb)
1803 {
1804 std::cout << "Error: wrong syntax at " << anArg << "\n";
1805 return 1;
1806 }
1807 aChangeSet->ToSetMaterial = 1;
1808 aChangeSet->MatName = theArgVec[anArgIter];
1809 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1810 }
1811 else if (anArg == "-unsetmat"
1812 || anArg == "-unsetmaterial")
1813 {
1814 aChangeSet->ToSetMaterial = -1;
1815 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1816 }
1817 else if (anArg == "-subshape"
1818 || anArg == "-subshapes")
1819 {
6262338c 1820 if (isDefaults)
1821 {
1822 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1823 return 1;
1824 }
1825
ad3217cd 1826 if (aNames.IsEmpty())
1827 {
1828 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1829 return 1;
1830 }
7fd59977 1831
ad3217cd 1832 aChanges.Append (ViewerTest_AspectsChangeSet());
1833 aChangeSet = &aChanges.ChangeLast();
7fd59977 1834
ad3217cd 1835 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1836 {
1837 Standard_CString aSubShapeName = theArgVec[anArgIter];
1838 if (*aSubShapeName == '-')
1839 {
1840 --anArgIter;
1841 break;
1842 }
7fd59977 1843
ad3217cd 1844 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1845 if (aSubShape.IsNull())
1846 {
1847 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1848 return 1;
1849 }
1850 aChangeSet->SubShapes.Append (aSubShape);
1851 }
7fd59977 1852
ad3217cd 1853 if (aChangeSet->SubShapes.IsEmpty())
1854 {
1855 std::cerr << "Error: empty list is specified after -subshapes!\n";
1856 return 1;
1857 }
1858 }
6262338c 1859 else if (anArg == "-freeboundary"
1860 || anArg == "-fb")
1861 {
1862 if (++anArgIter >= theArgNb)
1863 {
1864 std::cout << "Error: wrong syntax at " << anArg << "\n";
1865 return 1;
1866 }
1867 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1868 aValue.LowerCase();
1869 if (aValue == "on"
1870 || aValue == "1")
1871 {
1872 aChangeSet->ToSetShowFreeBoundary = 1;
1873 }
1874 else if (aValue == "off"
1875 || aValue == "0")
1876 {
1877 aChangeSet->ToSetShowFreeBoundary = -1;
1878 }
1879 else
1880 {
1881 std::cout << "Error: wrong syntax at " << anArg << "\n";
1882 return 1;
1883 }
1884 }
1885 else if (anArg == "-setfreeboundarywidth"
1886 || anArg == "-setfbwidth")
1887 {
1888 if (++anArgIter >= theArgNb)
1889 {
1890 std::cout << "Error: wrong syntax at " << anArg << "\n";
1891 return 1;
1892 }
1893 aChangeSet->ToSetFreeBoundaryWidth = 1;
1894 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
1895 }
1896 else if (anArg == "-unsetfreeboundarywidth"
1897 || anArg == "-unsetfbwidth")
1898 {
1899 aChangeSet->ToSetFreeBoundaryWidth = -1;
1900 aChangeSet->FreeBoundaryWidth = 1.0;
1901 }
1902 else if (anArg == "-setfreeboundarycolor"
1903 || anArg == "-setfbcolor")
1904 {
1905 Standard_Integer aNbComps = 0;
1906 Standard_Integer aCompIter = anArgIter + 1;
1907 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
1908 {
1909 if (theArgVec[aCompIter][0] == '-')
1910 {
1911 break;
1912 }
1913 }
1914 switch (aNbComps)
1915 {
1916 case 1:
1917 {
1918 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1919 Standard_CString aName = theArgVec[anArgIter + 1];
1920 if (!Quantity_Color::ColorFromName (aName, aColor))
1921 {
1922 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
1923 return 1;
1924 }
1925 aChangeSet->FreeBoundaryColor = aColor;
1926 break;
1927 }
1928 case 3:
1929 {
1930 Graphic3d_Vec3d anRgb;
1931 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1932 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1933 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1934 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1935 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1936 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1937 {
1938 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
1939 return 1;
1940 }
1941 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1942 break;
1943 }
1944 default:
1945 {
1946 std::cout << "Error: wrong syntax at " << anArg << "\n";
1947 return 1;
1948 }
1949 }
1950 aChangeSet->ToSetFreeBoundaryColor = 1;
1951 anArgIter += aNbComps;
1952 }
1953 else if (anArg == "-unsetfreeboundarycolor"
1954 || anArg == "-unsetfbcolor")
1955 {
1956 aChangeSet->ToSetFreeBoundaryColor = -1;
1957 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1958 }
ad3217cd 1959 else if (anArg == "-unset")
1960 {
5bffb882 1961 aChangeSet->ToSetVisibility = 1;
1962 aChangeSet->Visibility = 1;
ad3217cd 1963 aChangeSet->ToSetLineWidth = -1;
1964 aChangeSet->LineWidth = 1.0;
ac116c22 1965 aChangeSet->ToSetTypeOfLine = -1;
1966 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
ad3217cd 1967 aChangeSet->ToSetTransparency = -1;
1968 aChangeSet->Transparency = 0.0;
1969 aChangeSet->ToSetColor = -1;
1970 aChangeSet->Color = DEFAULT_COLOR;
1971 aChangeSet->ToSetMaterial = -1;
1972 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
6262338c 1973 aChangeSet->ToSetShowFreeBoundary = -1;
1974 aChangeSet->ToSetFreeBoundaryColor = -1;
1975 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
1976 aChangeSet->ToSetFreeBoundaryWidth = -1;
1977 aChangeSet->FreeBoundaryWidth = 1.0;
7fd59977 1978 }
7fd59977 1979 else
ad3217cd 1980 {
1981 std::cout << "Error: wrong syntax at " << anArg << "\n";
1982 return 1;
1983 }
7fd59977 1984 }
99c56d44 1985
ad3217cd 1986 Standard_Boolean isFirst = Standard_True;
1987 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
1988 aChangesIter.More(); aChangesIter.Next())
1989 {
1990 if (!aChangesIter.Value().Validate (!isFirst))
1991 {
1992 return 1;
1993 }
1994 isFirst = Standard_False;
99c56d44 1995 }
99c56d44 1996
ad3217cd 1997 if (aCtx->HasOpenedContext())
1998 {
1999 aCtx->CloseLocalContext();
99c56d44 2000 }
6262338c 2001
2002 // special case for -defaults parameter.
2003 // all changed values will be set to DefaultDrawer.
2004 if (isDefaults)
2005 {
2006 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2007
2008 if (aChangeSet->ToSetLineWidth != 0)
2009 {
2010 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2011 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2012 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2013 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2014 }
2015 if (aChangeSet->ToSetColor != 0)
2016 {
2017 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2018 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2019 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2020 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2021 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2022 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2023 }
ac116c22 2024 if (aChangeSet->ToSetTypeOfLine != 0)
2025 {
2026 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2027 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2028 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2029 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2030 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2031 }
6262338c 2032 if (aChangeSet->ToSetTransparency != 0)
2033 {
2034 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2035 }
2036 if (aChangeSet->ToSetMaterial != 0)
2037 {
2038 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2039 }
2040 if (aChangeSet->ToSetShowFreeBoundary == 1)
2041 {
2042 aDrawer->SetFreeBoundaryDraw (Standard_True);
2043 }
2044 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2045 {
2046 aDrawer->SetFreeBoundaryDraw (Standard_False);
2047 }
2048 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2049 {
2050 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2051 }
2052 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2053 {
2054 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2055 }
2056
2057 // redisplay all objects in context
2058 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2059 {
2060 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2061 if (!aPrs.IsNull())
2062 {
2063 aCtx->Redisplay (aPrs, Standard_False);
2064 }
2065 }
2066 return 0;
2067 }
2068
ad3217cd 2069 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2070 {
6262338c 2071 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2072 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2073 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 2074 Handle(AIS_ColoredShape) aColoredPrs;
2075 Standard_Boolean toDisplay = Standard_False;
6262338c 2076 Standard_Boolean toRedisplay = Standard_False;
5bffb882 2077 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 2078 {
2079 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2080 if (aShapePrs.IsNull())
2081 {
2082 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2083 return 1;
2084 }
2085 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2086 if (aColoredPrs.IsNull())
2087 {
2088 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2089 aCtx->Remove (aShapePrs, Standard_False);
2090 GetMapOfAIS().UnBind2 (aName);
2091 GetMapOfAIS().Bind (aColoredPrs, aName);
2092 toDisplay = Standard_True;
2093 aShapePrs = aColoredPrs;
2094 aPrs = aColoredPrs;
2095 }
2096 }
99c56d44 2097
ad3217cd 2098 if (!aPrs.IsNull())
2099 {
2100 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2101 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2102 if (aChangeSet->ToSetVisibility == 1)
2103 {
2104 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2105 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2106 }
2107 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2108 {
2109 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2110 }
2111 else if (aChangeSet->ToSetMaterial == -1)
2112 {
2113 aCtx->UnsetMaterial (aPrs, Standard_False);
2114 }
2115 if (aChangeSet->ToSetColor == 1)
2116 {
2117 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2118 }
2119 else if (aChangeSet->ToSetColor == -1)
2120 {
2121 aCtx->UnsetColor (aPrs, Standard_False);
2122 }
2123 if (aChangeSet->ToSetTransparency == 1)
2124 {
2125 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2126 }
2127 else if (aChangeSet->ToSetTransparency == -1)
2128 {
2129 aCtx->UnsetTransparency (aPrs, Standard_False);
2130 }
2131 if (aChangeSet->ToSetLineWidth == 1)
2132 {
2133 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2134 }
2135 else if (aChangeSet->ToSetLineWidth == -1)
2136 {
2137 aCtx->UnsetWidth (aPrs, Standard_False);
2138 }
6262338c 2139 if (!aDrawer.IsNull())
2140 {
2141 if (aChangeSet->ToSetShowFreeBoundary == 1)
2142 {
2143 aDrawer->SetFreeBoundaryDraw (Standard_True);
2144 toRedisplay = Standard_True;
2145 }
2146 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2147 {
2148 aDrawer->SetFreeBoundaryDraw (Standard_False);
2149 toRedisplay = Standard_True;
2150 }
2151 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2152 {
2153 Handle(Prs3d_LineAspect) aBoundaryAspect =
2154 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2155 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2156 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2157 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2158 toRedisplay = Standard_True;
2159 }
2160 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2161 {
2162 Handle(Prs3d_LineAspect) aBoundaryAspect =
2163 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2164 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2165 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2166 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2167 toRedisplay = Standard_True;
2168 }
ac116c22 2169 if (aChangeSet->ToSetTypeOfLine != 0)
2170 {
2171 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2172 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2173 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2174 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2175 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2176 toRedisplay = Standard_True;
2177 }
6262338c 2178 }
99c56d44 2179
ad3217cd 2180 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2181 {
2182 aChangeSet = &aChangesIter.ChangeValue();
2183 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2184 aSubShapeIter.More(); aSubShapeIter.Next())
2185 {
2186 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2187 if (aChangeSet->ToSetVisibility == 1)
2188 {
2189 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2190 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2191 }
ad3217cd 2192 if (aChangeSet->ToSetColor == 1)
2193 {
2194 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2195 }
2196 if (aChangeSet->ToSetLineWidth == 1)
2197 {
2198 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2199 }
2200 if (aChangeSet->ToSetColor == -1
2201 || aChangeSet->ToSetLineWidth == -1)
2202 {
2203 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2204 }
2205 }
2206 }
2207 if (toDisplay)
2208 {
2209 aCtx->Display (aPrs, Standard_False);
2210 }
6262338c 2211 if (toRedisplay)
2212 {
2213 aCtx->Redisplay (aPrs, Standard_False);
2214 }
ad3217cd 2215 else if (!aColoredPrs.IsNull())
2216 {
36132a2e 2217 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2218 }
99c56d44 2219 }
ad3217cd 2220 }
99c56d44 2221 return 0;
2222}
2223
7fd59977 2224//==============================================================================
2225//function : VDonly2
2226//author : ege
2227//purpose : Display only a selected or named object
519d35d8 2228// if there is no selected or named object s, nothing is done
7fd59977 2229//==============================================================================
519d35d8 2230static int VDonly2 (Draw_Interpretor& ,
2231 Standard_Integer theArgNb,
2232 const char** theArgVec)
7fd59977 2233{
519d35d8 2234 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2235 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2236 if (aCtx.IsNull())
2237 {
2238 std::cerr << "Error: no active view!\n";
7fd59977 2239 return 1;
519d35d8 2240 }
7fd59977 2241
519d35d8 2242 if (aCtx->HasOpenedContext())
2243 {
2244 aCtx->CloseLocalContext();
2245 }
7fd59977 2246
519d35d8 2247 Standard_Integer anArgIter = 1;
2248 for (; anArgIter < theArgNb; ++anArgIter)
2249 {
4e18052b 2250 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2251 {
2252 break;
2253 }
2254 }
7fd59977 2255
519d35d8 2256 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2257 if (anArgIter >= theArgNb)
2258 {
2259 // display only selected objects
2260 if (aCtx->NbCurrents() < 1)
2261 {
2262 return 0;
7fd59977 2263 }
2264
519d35d8 2265 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2266 {
2267 aDispSet.Add (aCtx->Current());
2268 }
2269 }
2270 else
2271 {
2272 // display only specified objects
2273 for (; anArgIter < theArgNb; ++anArgIter)
2274 {
2275 TCollection_AsciiString aName = theArgVec[anArgIter];
2276 if (GetMapOfAIS().IsBound2 (aName))
2277 {
d09dda09 2278 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2279 if (!aShape.IsNull())
519d35d8 2280 {
519d35d8 2281 aCtx->Display (aShape, Standard_False);
d09dda09 2282 aDispSet.Add (aShape);
519d35d8 2283 }
7fd59977 2284 }
2285 }
7fd59977 2286 }
519d35d8 2287
2288 // weed out other objects
2289 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2290 {
2291 if (aDispSet.Contains (anIter.Key1()))
2292 {
2293 continue;
2294 }
2295
d09dda09 2296 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2297 if (aShape.IsNull())
519d35d8 2298 {
519d35d8 2299 aCtx->Erase (aShape, Standard_False);
2300 }
519d35d8 2301 }
7fd59977 2302 return 0;
2303}
2304
2305//==============================================================================
eef7fc64 2306//function : VRemove
2307//purpose : Removes selected or named objects.
2308// If there is no selected or named objects,
2309// all objects in the viewer can be removed with argument -all.
2310// If -context is in arguments, the object is not deleted from the map of
2311// objects (deleted only from the current context).
2312//==============================================================================
2313int VRemove (Draw_Interpretor& theDI,
519d35d8 2314 Standard_Integer theArgNb,
2315 const char** theArgVec)
eef7fc64 2316{
4e18052b 2317 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2318 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2319 if (aCtx.IsNull())
eef7fc64 2320 {
b6d587e3 2321 std::cerr << "Error: no active view!\n";
eef7fc64 2322 return 1;
2323 }
2324
4e18052b 2325 Standard_Boolean isContextOnly = Standard_False;
2326 Standard_Boolean toRemoveAll = Standard_False;
2327 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2328 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2329
2330 Standard_Integer anArgIter = 1;
2331 for (; anArgIter < theArgNb; ++anArgIter)
2332 {
2333 TCollection_AsciiString anArg = theArgVec[anArgIter];
2334 anArg.LowerCase();
2335 if (anArg == "-context")
2336 {
2337 isContextOnly = Standard_True;
2338 }
2339 else if (anArg == "-all")
2340 {
2341 toRemoveAll = Standard_True;
2342 }
b7cd4ba7 2343 else if (anArg == "-noinfo")
2344 {
2345 toPrintInfo = Standard_False;
2346 }
b6d587e3 2347 else if (anArg == "-local")
2348 {
2349 toRemoveLocal = Standard_True;
2350 }
2351 else if (anUpdateTool.parseRedrawMode (anArg))
2352 {
2353 continue;
2354 }
2355 else
519d35d8 2356 {
2357 break;
2358 }
2359 }
2360 if (toRemoveAll
2361 && anArgIter < theArgNb)
2362 {
b6d587e3 2363 std::cerr << "Error: wrong syntax!\n";
2364 return 1;
2365 }
2366
2367 if (toRemoveLocal && !aCtx->HasOpenedContext())
2368 {
2369 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2370 return 1;
2371 }
b6d587e3 2372 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2373 {
2374 aCtx->CloseAllContexts (Standard_False);
2375 }
519d35d8 2376
eef7fc64 2377 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2378 if (toRemoveAll)
eef7fc64 2379 {
2380 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2381 anIter.More(); anIter.Next())
2382 {
2383 anIONameList.Append (anIter.Key2());
2384 }
2385 }
519d35d8 2386 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2387 {
519d35d8 2388 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2389 {
519d35d8 2390 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2391 if (!GetMapOfAIS().IsBound2 (aName))
2392 {
2393 theDI << aName.ToCString() << " was not bound to some object.\n";
2394 continue;
2395 }
2396
d09dda09 2397 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2398 if (anIO->GetContext() != aCtx)
eef7fc64 2399 {
d09dda09 2400 theDI << aName.ToCString() << " was not displayed in current context.\n";
2401 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 2402 continue;
2403 }
2404
d09dda09 2405 anIONameList.Append (aName);
2406 continue;
eef7fc64 2407 }
2408 }
d09dda09 2409 else if (aCtx->NbCurrents() > 0)
eef7fc64 2410 {
2411 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2412 anIter.More(); anIter.Next())
2413 {
2414 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
d09dda09 2415 if (!aCtx->IsCurrent (anIO))
eef7fc64 2416 {
eef7fc64 2417 continue;
2418 }
2419
d09dda09 2420 anIONameList.Append (anIter.Key2());
2421 continue;
eef7fc64 2422 }
2423 }
2424
2425 // Unbind all removed objects from the map of displayed IO.
2426 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2427 anIter.More(); anIter.Next())
2428 {
519d35d8 2429 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
d09dda09 2430 aCtx->Remove (anIO, Standard_False);
2431 if (toPrintInfo)
519d35d8 2432 {
d09dda09 2433 theDI << anIter.Value().ToCString() << " was removed\n";
519d35d8 2434 }
519d35d8 2435 if (!isContextOnly)
2436 {
2437 GetMapOfAIS().UnBind2 (anIter.Value());
2438 }
2439 }
b6d587e3 2440
2441 // Close local context if it is empty
2442 TColStd_MapOfTransient aLocalIO;
2443 if (aCtx->HasOpenedContext()
2444 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2445 {
2446 aCtx->CloseAllContexts (Standard_False);
2447 }
2448
eef7fc64 2449 return 0;
2450}
2451
2452//==============================================================================
b514beda 2453//function : VErase
2454//purpose : Erase some selected or named objects
7fd59977 2455// if there is no selected or named objects, the whole viewer is erased
7fd59977 2456//==============================================================================
b514beda 2457int VErase (Draw_Interpretor& theDI,
2458 Standard_Integer theArgNb,
2459 const char** theArgVec)
7fd59977 2460{
a1954302 2461 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2462 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2463 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2464 if (aCtx.IsNull())
b514beda 2465 {
b6d587e3 2466 std::cerr << "Error: no active view!\n";
7fd59977 2467 return 1;
b514beda 2468 }
519d35d8 2469
519d35d8 2470 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2471
2472 Standard_Integer anArgIter = 1;
a272ed94 2473 Standard_Boolean toEraseLocal = Standard_False;
2474 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2475 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2476 for (; anArgIter < theArgNb; ++anArgIter)
2477 {
b6d587e3 2478 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2479 anArgCase.LowerCase();
2480 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2481 {
b6d587e3 2482 continue;
2483 }
2484 else if (anArgCase == "-local")
2485 {
2486 toEraseLocal = Standard_True;
2487 }
a272ed94 2488 else if (anArgCase == "-view"
2489 || anArgCase == "-inview")
2490 {
2491 toEraseInView = Standard_True;
2492 }
b6d587e3 2493 else
2494 {
2495 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2496 }
2497 }
2498
b6d587e3 2499 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2500 {
b6d587e3 2501 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2502 return 1;
2503 }
7fd59977 2504
b6d587e3 2505 if (toEraseLocal && !aCtx->HasOpenedContext())
2506 {
2507 std::cerr << "Error: local selection context is not open.\n";
2508 return 1;
2509 }
2510 else if (!toEraseLocal && aCtx->HasOpenedContext())
2511 {
2512 aCtx->CloseAllContexts (Standard_False);
2513 }
2514
2515 if (!aNamesOfEraseIO.IsEmpty())
2516 {
2517 // Erase named objects
2518 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2519 {
b6d587e3 2520 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2521 if (!GetMapOfAIS().IsBound2 (aName))
2522 {
2523 continue;
2524 }
7fd59977 2525
b514beda 2526 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2527 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2528 theDI << aName.ToCString() << " ";
2529 if (!anIO.IsNull())
2530 {
a272ed94 2531 if (toEraseInView)
2532 {
2533 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2534 }
2535 else
2536 {
2537 aCtx->Erase (anIO, Standard_False);
2538 }
b514beda 2539 }
7fd59977 2540 }
7fd59977 2541 }
b6d587e3 2542 else if (!toEraseAll && aCtx->NbCurrents() > 0)
b514beda 2543 {
b6d587e3 2544 // Erase selected objects
b514beda 2545 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2546 anIter.More(); anIter.Next())
2547 {
2548 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2549 if (!anIO.IsNull()
4e18052b 2550 && aCtx->IsCurrent (anIO))
b514beda 2551 {
2552 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2553 if (toEraseInView)
2554 {
2555 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2556 }
2557 else
2558 {
2559 aCtx->Erase (anIO, Standard_False);
2560 }
7fd59977 2561 }
2562 }
b514beda 2563 }
519d35d8 2564 else
b514beda 2565 {
b6d587e3 2566 // Erase all objects
519d35d8 2567 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2568 anIter.More(); anIter.Next())
b514beda 2569 {
519d35d8 2570 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2571 if (!anIO.IsNull())
2572 {
a272ed94 2573 if (toEraseInView)
2574 {
2575 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2576 }
2577 else
2578 {
2579 aCtx->Erase (anIO, Standard_False);
2580 }
519d35d8 2581 }
7fd59977 2582 }
7fd59977 2583 }
b6d587e3 2584
7fd59977 2585 return 0;
2586}
2587
7fd59977 2588//==============================================================================
2589//function : VDisplayAll
2590//author : ege
2591//purpose : Display all the objects of the Map
7fd59977 2592//==============================================================================
519d35d8 2593static int VDisplayAll (Draw_Interpretor& ,
2594 Standard_Integer theArgNb,
2595 const char** theArgVec)
7fd59977 2596
2597{
4e18052b 2598 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2599 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2600 if (aCtx.IsNull())
519d35d8 2601 {
b6d587e3 2602 std::cerr << "Error: no active view!\n";
519d35d8 2603 return 1;
2604 }
2605
519d35d8 2606 Standard_Integer anArgIter = 1;
b6d587e3 2607 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2608 for (; anArgIter < theArgNb; ++anArgIter)
2609 {
b6d587e3 2610 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2611 anArgCase.LowerCase();
2612 if (anArgCase == "-local")
2613 {
2614 toDisplayLocal = Standard_True;
2615 }
2616 else if (anUpdateTool.parseRedrawMode (anArgCase))
2617 {
2618 continue;
2619 }
2620 else
519d35d8 2621 {
2622 break;
7fd59977 2623 }
519d35d8 2624 }
2625 if (anArgIter < theArgNb)
2626 {
2627 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2628 return 1;
2629 }
2630
b6d587e3 2631 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2632 {
b6d587e3 2633 std::cerr << "Error: local selection context is not open.\n";
2634 return 1;
2635 }
2636 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2637 {
2638 aCtx->CloseLocalContext (Standard_False);
519d35d8 2639 }
2640
2641 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2642 anIter.More(); anIter.Next())
2643 {
d09dda09 2644 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2645 aCtx->Erase (aShape, Standard_False);
519d35d8 2646 }
2647
2648 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2649 anIter.More(); anIter.Next())
2650 {
d09dda09 2651 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2652 aCtx->Display (aShape, Standard_False);
7fd59977 2653 }
2654 return 0;
2655}
2656
c2a388f8 2657//! Auxiliary method to find presentation
2658inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2659 const Handle(AIS_InteractiveObject)& theIO,
2660 const Standard_Integer theMode)
2661{
2662 if (theIO.IsNull())
2663 {
2664 return Handle(PrsMgr_Presentation)();
2665 }
2666
2667 if (theMode != -1)
2668 {
2669 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2670 {
2671 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2672 }
2673 }
2674 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2675 {
2676 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2677 }
2678 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2679 {
2680 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2681 }
2682 return Handle(PrsMgr_Presentation)();
2683}
2684
2685enum ViewerTest_BndAction
2686{
2687 BndAction_Hide,
2688 BndAction_Show,
2689 BndAction_Print
2690};
2691
2692//! Auxiliary method to print bounding box of presentation
2693inline void bndPresentation (Draw_Interpretor& theDI,
2694 const Handle(PrsMgr_Presentation)& thePrs,
2695 const TCollection_AsciiString& theName,
2696 const ViewerTest_BndAction theAction)
2697{
2698 switch (theAction)
2699 {
2700 case BndAction_Hide:
2701 {
2702 thePrs->Presentation()->GraphicUnHighlight();
2703 break;
2704 }
2705 case BndAction_Show:
2706 {
a1954302 2707 Handle(Graphic3d_Structure) aPrs = thePrs->Presentation();
2708 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2709 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2710 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2711 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
c2a388f8 2712 break;
2713 }
2714 case BndAction_Print:
2715 {
ed063270 2716 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2717 gp_Pnt aMin = aBox.CornerMin();
2718 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 2719 theDI << theName << "\n"
ed063270 2720 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2721 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 2722 break;
2723 }
2724 }
2725}
2726
2727//==============================================================================
2728//function : VBounding
2729//purpose :
2730//==============================================================================
2731int VBounding (Draw_Interpretor& theDI,
2732 Standard_Integer theArgNb,
2733 const char** theArgVec)
2734{
2735 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2736 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2737 if (aCtx.IsNull())
2738 {
2739 std::cout << "Error: no active view!\n";
2740 return 1;
2741 }
2742
4e18052b 2743 ViewerTest_BndAction anAction = BndAction_Show;
2744 Standard_Integer aMode = -1;
c2a388f8 2745
2746 Standard_Integer anArgIter = 1;
2747 for (; anArgIter < theArgNb; ++anArgIter)
2748 {
2749 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2750 anArg.LowerCase();
2751 if (anArg == "-print")
2752 {
2753 anAction = BndAction_Print;
2754 }
2755 else if (anArg == "-show")
2756 {
2757 anAction = BndAction_Show;
2758 }
2759 else if (anArg == "-hide")
2760 {
2761 anAction = BndAction_Hide;
2762 }
2763 else if (anArg == "-mode")
2764 {
2765 if (++anArgIter >= theArgNb)
2766 {
2767 std::cout << "Error: wrong syntax at " << anArg << "\n";
2768 return 1;
2769 }
2770 aMode = Draw::Atoi (theArgVec[anArgIter]);
2771 }
4e18052b 2772 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 2773 {
2774 break;
2775 }
2776 }
2777
2778 if (anArgIter < theArgNb)
2779 {
2780 // has a list of names
2781 for (; anArgIter < theArgNb; ++anArgIter)
2782 {
2783 TCollection_AsciiString aName = theArgVec[anArgIter];
2784 if (!GetMapOfAIS().IsBound2 (aName))
2785 {
2786 std::cout << "Error: presentation " << aName << " does not exist\n";
2787 return 1;
2788 }
2789
2790 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2791 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2792 if (aPrs.IsNull())
2793 {
2794 std::cout << "Error: presentation " << aName << " does not exist\n";
2795 return 1;
2796 }
2797 bndPresentation (theDI, aPrs, aName, anAction);
2798 }
2799 }
4e18052b 2800 else if (aCtx->NbCurrents() > 0)
c2a388f8 2801 {
2802 // remove all currently selected objects
2803 for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent())
2804 {
2805 Handle(AIS_InteractiveObject) anIO = aCtx->Current();
2806 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2807 if (!aPrs.IsNull())
2808 {
2809 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
2810 }
2811 }
2812 }
2813 else
2814 {
2815 // all objects
2816 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2817 anIter.More(); anIter.Next())
2818 {
2819 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2820 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
2821 if (!aPrs.IsNull())
2822 {
2823 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
2824 }
2825 }
2826 }
c2a388f8 2827 return 0;
2828}
2829
d399d3c3 2830//==============================================================================
2831//function : VTexture
2832//purpose :
2833//==============================================================================
2834Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 2835{
d399d3c3 2836 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 2837
900f7229 2838 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 2839 if (aCommandName == "vtexture")
2840 {
2841 if (theArgsNb < 2)
7fd59977 2842 {
d399d3c3 2843 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2844 std::cout << "Type help for more information.\n";
31160f80 2845 return 1;
7fd59977 2846 }
2847
d399d3c3 2848 // look for options of vtexture command
2849 TCollection_AsciiString aParseKey;
2850 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
2851 {
2852 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 2853
d399d3c3 2854 anArg.UpperCase();
2855 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
2856 {
2857 aParseKey = anArg;
2858 aParseKey.Remove (1);
2859 aParseKey.UpperCase();
900f7229 2860 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 2861 continue;
2862 }
2863
2864 if (aParseKey.IsEmpty())
2865 {
2866 continue;
2867 }
2868
900f7229 2869 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 2870 }
2871 }
2872 else if (aCommandName == "vtexscale"
2873 || aCommandName == "vtexorigin"
2874 || aCommandName == "vtexrepeat")
2875 {
2876 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
2877 // equal to -scale, -origin, -repeat options of vtexture command
2878 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 2879 {
d399d3c3 2880 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
2881 std::cout << "Type help for more information.\n";
31160f80 2882 return 1;
7fd59977 2883 }
2884
900f7229 2885 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 2886 if (theArgsNb == 2)
2887 {
900f7229 2888 anArgs->Append ("OFF");
d399d3c3 2889 }
2890 else if (theArgsNb == 4)
2891 {
900f7229 2892 anArgs->Append (TCollection_AsciiString (theArgv[2]));
2893 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 2894 }
7fd59977 2895
d399d3c3 2896 TCollection_AsciiString anArgKey;
2897 if (aCommandName == "vtexscale")
2898 {
2899 anArgKey = "SCALE";
2900 }
2901 else if (aCommandName == "vtexorigin")
2902 {
2903 anArgKey = "ORIGIN";
2904 }
2905 else
2906 {
2907 anArgKey = "REPEAT";
2908 }
2909
2910 aMapOfArgs.Bind (anArgKey, anArgs);
2911 }
2912 else if (aCommandName == "vtexdefault")
7fd59977 2913 {
d399d3c3 2914 // scan for parameters of vtexdefault command
2915 // equal to -default option of vtexture command
900f7229 2916 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 2917 }
2918
d399d3c3 2919 // Check arguments for validity
900f7229 2920 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 2921 for (; aMapIt.More(); aMapIt.Next())
2922 {
2923 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 2924 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 2925
2926 // -scale, -origin, -repeat: one argument "off", or two real values
2927 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 2928 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
2929 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 2930 {
d399d3c3 2931 continue;
7fd59977 2932 }
d399d3c3 2933
2934 // -modulate: single argument "on" / "off"
900f7229 2935 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 2936 {
2937 continue;
2938 }
2939
2940 // -default: no arguments
900f7229 2941 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 2942 {
2943 continue;
2944 }
2945
2946 TCollection_AsciiString aLowerKey;
2947 aLowerKey = "-";
2948 aLowerKey += aKey;
2949 aLowerKey.LowerCase();
2950 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
2951 std::cout << "Type help for more information.\n";
2952 return 1;
2953 }
2954
2955 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
2956 if (anAISContext.IsNull())
2957 {
2958 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
2959 return 1;
2960 }
2961
2962 Standard_Integer aPreviousMode = 0;
2963
2964 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
2965
2966 TCollection_AsciiString aShapeName (theArgv[1]);
2967 Handle(AIS_InteractiveObject) anIO;
2968
2969 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
2970 if (aMapOfIO.IsBound2 (aShapeName))
2971 {
2972 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
2973 }
2974
2975 if (anIO.IsNull())
2976 {
2977 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
2978 return 1;
2979 }
2980
2981 Handle(AIS_TexturedShape) aTexturedIO;
2982 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
2983 {
2984 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
2985 aPreviousMode = aTexturedIO->DisplayMode();
2986 }
7fd59977 2987 else
d399d3c3 2988 {
2195ab96 2989 anAISContext->Remove (anIO, Standard_False);
d399d3c3 2990 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
2991 GetMapOfAIS().UnBind1 (anIO);
2992 GetMapOfAIS().UnBind2 (aShapeName);
2993 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
2994 }
2995
2996 // -------------------------------------------
2997 // Turn texturing on/off - only for vtexture
2998 // -------------------------------------------
2999
3000 if (aCommandName == "vtexture")
3001 {
3002 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3003
3004 if (aTextureArg.IsEmpty())
7fd59977 3005 {
d399d3c3 3006 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3007 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3008
3009 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3010 if (aPreviousMode == 3)
3011 {
3012 anAISContext->RecomputePrsOnly (aTexturedIO);
3013 }
3014
3015 anAISContext->Display (aTexturedIO, Standard_True);
3016 return 0;
7fd59977 3017 }
d399d3c3 3018 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3019 {
d399d3c3 3020 if (aTextureArg == "?")
3021 {
3022 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3023
d399d3c3 3024 theDi << "\n Files in current directory : \n" << "\n";
3025 theDi.Eval ("glob -nocomplain *");
7fd59977 3026
d399d3c3 3027 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3028 aCmnd += aTextureFolder;
3029 aCmnd += "/* ";
7fd59977 3030
d399d3c3 3031 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3032 theDi.Eval (aCmnd.ToCString());
3033 return 0;
3034 }
3035 else
3036 {
3037 aTexturedIO->SetTextureFileName (aTextureArg);
3038 }
3039 }
3040 }
7fd59977 3041
d399d3c3 3042 // ------------------------------------
3043 // Process other options and commands
3044 // ------------------------------------
7fd59977 3045
900f7229 3046 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3047 if (aMapOfArgs.Find ("DEFAULT", aValues))
3048 {
3049 aTexturedIO->SetTextureRepeat (Standard_False);
3050 aTexturedIO->SetTextureOrigin (Standard_False);
3051 aTexturedIO->SetTextureScale (Standard_False);
3052 aTexturedIO->EnableTextureModulate();
3053 }
3054 else
3055 {
3056 if (aMapOfArgs.Find ("SCALE", aValues))
3057 {
900f7229 3058 if (aValues->Value(1) != "OFF")
d399d3c3 3059 {
900f7229 3060 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3061 }
7fd59977 3062 else
d399d3c3 3063 {
3064 aTexturedIO->SetTextureScale (Standard_False);
3065 }
3066 }
7fd59977 3067
d399d3c3 3068 if (aMapOfArgs.Find ("ORIGIN", aValues))
3069 {
900f7229 3070 if (aValues->Value(1) != "OFF")
d399d3c3 3071 {
900f7229 3072 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3073 }
3074 else
3075 {
3076 aTexturedIO->SetTextureOrigin (Standard_False);
3077 }
3078 }
7fd59977 3079
d399d3c3 3080 if (aMapOfArgs.Find ("REPEAT", aValues))
3081 {
900f7229 3082 if (aValues->Value(1) != "OFF")
d399d3c3 3083 {
900f7229 3084 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3085 }
3086 else
3087 {
3088 aTexturedIO->SetTextureRepeat (Standard_False);
3089 }
7fd59977 3090 }
3091
d399d3c3 3092 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 3093 {
900f7229 3094 if (aValues->Value(1) == "ON")
d399d3c3 3095 {
3096 aTexturedIO->EnableTextureModulate();
3097 }
3098 else
3099 {
3100 aTexturedIO->DisableTextureModulate();
3101 }
7fd59977 3102 }
d399d3c3 3103 }
3104
3105 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3106 {
3107 anAISContext->RecomputePrsOnly (aTexturedIO);
3108 }
3109 else
3110 {
3111 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3112 anAISContext->Display (aTexturedIO, Standard_True);
3113 anAISContext->Update (aTexturedIO,Standard_True);
3114 }
3115
31160f80 3116 return 0;
7fd59977 3117}
3118
af65fb19 3119//! Auxiliary method to parse transformation persistence flags
3120inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3121 Standard_Integer& theFlags)
3122{
3123 if (theFlagString == "pan")
3124 {
3125 theFlags |= Graphic3d_TMF_PanPers;
3126 }
3127 else if (theFlagString == "zoom")
3128 {
3129 theFlags |= Graphic3d_TMF_ZoomPers;
3130 }
3131 else if (theFlagString == "rotate")
3132 {
3133 theFlags |= Graphic3d_TMF_RotatePers;
3134 }
3135 else if (theFlagString == "trihedron")
3136 {
3137 theFlags = Graphic3d_TMF_TriedronPers;
3138 }
3139 else if (theFlagString == "full")
3140 {
3141 theFlags = Graphic3d_TMF_FullPers;
3142 }
3143 else if (theFlagString == "none")
3144 {
3145 theFlags = Graphic3d_TMF_None;
3146 }
3147 else
3148 {
3149 return Standard_False;
3150 }
3151
3152 return Standard_True;
3153}
3154
7fd59977 3155//==============================================================================
3156//function : VDisplay2
3157//author : ege
3158//purpose : Display an object from its name
7fd59977 3159//==============================================================================
519d35d8 3160static int VDisplay2 (Draw_Interpretor& theDI,
3161 Standard_Integer theArgNb,
3162 const char** theArgVec)
7fd59977 3163{
519d35d8 3164 if (theArgNb < 2)
3165 {
b6d587e3 3166 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 3167 return 1;
3168 }
b6d587e3 3169
3170 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3171 if (aCtx.IsNull())
519d35d8 3172 {
7fd59977 3173 ViewerTest::ViewerInit();
4e18052b 3174 aCtx = ViewerTest::GetAISContext();
7fd59977 3175 }
3176
b6d587e3 3177 // Parse input arguments
4e18052b 3178 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 3179 Standard_Integer isMutable = -1;
3180 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3181 Standard_Boolean toDisplayLocal = Standard_False;
3182 Standard_Boolean toReDisplay = Standard_False;
af65fb19 3183 Standard_Integer isSelectable = -1;
3184 Standard_Integer anObjDispMode = -2;
3185 Standard_Integer anObjHighMode = -2;
3186 Standard_Boolean toSetTrsfPers = Standard_False;
3187 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3188 gp_Pnt aTPPosition;
b6d587e3 3189 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 3190 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94 3191 Standard_Integer toDisplayInView = Standard_False;
519d35d8 3192 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3193 {
b7cd4ba7 3194 const TCollection_AsciiString aName = theArgVec[anArgIter];
3195 TCollection_AsciiString aNameCase = aName;
3196 aNameCase.LowerCase();
4e18052b 3197 if (anUpdateTool.parseRedrawMode (aName))
519d35d8 3198 {
3199 continue;
3200 }
b7cd4ba7 3201 else if (aNameCase == "-mutable")
3202 {
3203 isMutable = 1;
b7cd4ba7 3204 }
a1954302 3205 else if (aNameCase == "-neutral")
3206 {
3207 aDispStatus = AIS_DS_Displayed;
3208 }
3209 else if (aNameCase == "-immediate"
3210 || aNameCase == "-top")
3211 {
3212 aZLayer = Graphic3d_ZLayerId_Top;
3213 }
3214 else if (aNameCase == "-topmost")
3215 {
3216 aZLayer = Graphic3d_ZLayerId_Topmost;
3217 }
3218 else if (aNameCase == "-osd"
af65fb19 3219 || aNameCase == "-toposd"
3220 || aNameCase == "-overlay")
a1954302 3221 {
3222 aZLayer = Graphic3d_ZLayerId_TopOSD;
3223 }
af65fb19 3224 else if (aNameCase == "-botosd"
3225 || aNameCase == "-underlay")
3226 {
3227 aZLayer = Graphic3d_ZLayerId_BotOSD;
3228 }
3229 else if (aNameCase == "-select"
3230 || aNameCase == "-selectable")
3231 {
3232 isSelectable = 1;
3233 }
3234 else if (aNameCase == "-noselect"
3235 || aNameCase == "-noselection")
3236 {
3237 isSelectable = 0;
3238 }
3239 else if (aNameCase == "-dispmode"
3240 || aNameCase == "-displaymode")
3241 {
3242 if (++anArgIter >= theArgNb)
3243 {
3244 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3245 return 1;
3246 }
3247
3248 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3249 }
3250 else if (aNameCase == "-highmode"
3251 || aNameCase == "-highlightmode")
3252 {
3253 if (++anArgIter >= theArgNb)
3254 {
3255 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3256 return 1;
3257 }
3258
3259 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3260 }
3261 else if (aNameCase == "-3d")
3262 {
3263 toSetTrsfPers = Standard_True;
3264 aTrsfPersFlags = Graphic3d_TMF_None;
3265 }
3266 else if (aNameCase == "-2d")
3267 {
3268 toSetTrsfPers = Standard_True;
3269 aTrsfPersFlags = Graphic3d_TMF_2d;
3270 }
3271 else if (aNameCase == "-2dtopdown")
3272 {
3273 toSetTrsfPers = Standard_True;
3274 aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
3275 }
3276 else if (aNameCase == "-trsfpers"
3277 || aNameCase == "-pers")
3278 {
3279 if (++anArgIter >= theArgNb)
3280 {
3281 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3282 return 1;
3283 }
3284
3285 toSetTrsfPers = Standard_True;
3286 aTrsfPersFlags = Graphic3d_TMF_None;
3287 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3288 aPersFlags.LowerCase();
3289 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3290 {
3291 if (aParserPos == -1)
3292 {
3293 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3294 {
3295 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3296 return 1;
3297 }
3298 break;
3299 }
3300
3301 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3302 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3303 {
3304 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3305 return 1;
3306 }
3307 aPersFlags = anOtherFlags;
3308 }
3309 }
3310 else if (aNameCase == "-trsfperspos"
3311 || aNameCase == "-perspos")
3312 {
3313 if (anArgIter + 2 >= theArgNb)
3314 {
3315 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3316 return 1;
3317 }
3318
3319 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3320 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3321 TCollection_AsciiString aZ = "0";
3322 if (!aX.IsIntegerValue()
3323 || !aY.IsIntegerValue())
3324 {
3325 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3326 return 1;
3327 }
3328 if (anArgIter + 1 < theArgNb)
3329 {
3330 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3331 if (aTemp.IsIntegerValue())
3332 {
3333 aZ = aTemp;
3334 ++anArgIter;
3335 }
3336 }
3337 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3338 }
a1954302 3339 else if (aNameCase == "-layer")
3340 {
3341 if (++anArgIter >= theArgNb)
3342 {
3343 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3344 return 1;
3345 }
3346
3347 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3348 if (!aValue.IsIntegerValue())
3349 {
3350 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3351 return 1;
3352 }
3353
3354 aZLayer = aValue.IntegerValue();
3355 }
a272ed94 3356 else if (aNameCase == "-view"
3357 || aNameCase == "-inview")
3358 {
3359 toDisplayInView = Standard_True;
3360 }
b6d587e3 3361 else if (aNameCase == "-local")
3362 {
a1954302 3363 aDispStatus = AIS_DS_Temporary;
b6d587e3 3364 toDisplayLocal = Standard_True;
3365 }
a1954302 3366 else if (aNameCase == "-redisplay")
3367 {
3368 toReDisplay = Standard_True;
3369 }
b6d587e3 3370 else
3371 {
3372 aNamesOfDisplayIO.Append (aName);
3373 }
3374 }
3375
3376 if (aNamesOfDisplayIO.IsEmpty())
3377 {
3378 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3379 return 1;
3380 }
3381
3382 // Prepare context for display
3383 if (toDisplayLocal && !aCtx->HasOpenedContext())
3384 {
3385 aCtx->OpenLocalContext (Standard_False);
3386 }
3387 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3388 {
3389 aCtx->CloseAllContexts (Standard_False);
3390 }
3391
3392 // Display interactive objects
3393 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3394 {
3395 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3396
3397 if (!GetMapOfAIS().IsBound2 (aName))
519d35d8 3398 {
3399 // create the AIS_Shape from a name
3400 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3401 if (!aShape.IsNull())
3402 {
b7cd4ba7 3403 if (isMutable != -1)
3404 {
3405 aShape->SetMutable (isMutable == 1);
3406 }
a1954302 3407 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3408 {
3409 aShape->SetZLayer (aZLayer);
3410 }
af65fb19 3411 if (toSetTrsfPers)
3412 {
3413 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3414 }
3415 if (anObjDispMode != -2)
3416 {
3417 aShape->SetDisplayMode (anObjDispMode);
3418 }
3419 if (anObjHighMode != -2)
3420 {
3421 aShape->SetHilightMode (anObjHighMode);
3422 }
b3c433fe 3423 if (!toDisplayLocal)
3424 GetMapOfAIS().Bind (aShape, aName);
a1954302 3425
3426 Standard_Integer aDispMode = aShape->HasDisplayMode()
3427 ? aShape->DisplayMode()
3428 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3429 ? aCtx->DisplayMode()
3430 : 0);
af65fb19 3431 Standard_Integer aSelMode = -1;
3432 if ( isSelectable == 1
3433 || (isSelectable == -1
3434 && aCtx->GetAutoActivateSelection()
3435 && aShape->GetTransformPersistenceMode() == 0))
3436 {
3437 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3438 }
a1954302 3439
3440 aCtx->Display (aShape, aDispMode, aSelMode,
3441 Standard_False, aShape->AcceptShapeDecomposition(),
3442 aDispStatus);
a272ed94 3443 if (toDisplayInView)
3444 {
3445 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3446 {
3447 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3448 }
3449 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3450 }
519d35d8 3451 }
af65fb19 3452 else
3453 {
3454 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3455 }
519d35d8 3456 continue;
3457 }
7fd59977 3458
d09dda09 3459 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3460 if (isMutable != -1)
519d35d8 3461 {
d09dda09 3462 aShape->SetMutable (isMutable == 1);
3463 }
3464 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3465 {
3466 aShape->SetZLayer (aZLayer);
3467 }
3468 if (toSetTrsfPers)
3469 {
3470 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3471 }
3472 if (anObjDispMode != -2)
3473 {
3474 aShape->SetDisplayMode (anObjDispMode);
3475 }
3476 if (anObjHighMode != -2)
3477 {
3478 aShape->SetHilightMode (anObjHighMode);
3479 }
3480 Standard_Integer aDispMode = aShape->HasDisplayMode()
3481 ? aShape->DisplayMode()
3482 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3483 ? aCtx->DisplayMode()
3484 : 0);
3485 Standard_Integer aSelMode = -1;
3486 if ( isSelectable == 1
3487 || (isSelectable == -1
3488 && aCtx->GetAutoActivateSelection()
3489 && aShape->GetTransformPersistenceMode() == 0))
3490 {
3491 aSelMode = aShape->HasSelectionMode() ? aShape->SelectionMode() : -1;
3492 }
3493
3494 if (aShape->Type() == AIS_KOI_Datum)
3495 {
3496 aCtx->Display (aShape, Standard_False);
3497 }
3498 else
3499 {
3500 theDI << "Display " << aName.ToCString() << "\n";
3501
3502 // update the Shape in the AIS_Shape
3503 TopoDS_Shape aNew