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