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