0026371: Implementation of new entities for GD&T
[occt.git] / src / ViewerTest / ViewerTest.cxx
Content-type: text/html OCCT Git - occt.git/blame - src/ViewerTest/ViewerTest.cxx


500 - Internal Server Error

Malformed UTF-8 character (fatal) at (eval 8) line 1, <$fd> line 12223.
CommitLineData
b311480e 1// Created on: 1997-07-23
2// Created by: Henri JEANNIN
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
7fd59977 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
17// Modified by Eric Gouthiere [sep-oct 98] -> add commands for display...
7fd59977 18// Modified by Robert Coublanc [nov 16-17-18 1998]
19// -split ViewerTest.cxx into 3 files : ViewerTest.cxx,
20// ViewerTest_ObjectCommands.cxx
21// ViewerTest_RelationCommands.cxx
22// -add Functions and commands for interactive selection of shapes and objects
23// in AIS Viewers. (PickShape(s), PickObject(s),
24
25#include <Standard_Stream.hxx>
26
27#include <ViewerTest.hxx>
189f85a3 28#include <ViewerTest_CmdParser.hxx>
4e18052b 29
7fd59977 30#include <TopLoc_Location.hxx>
31#include <TopTools_HArray1OfShape.hxx>
32#include <TColStd_HArray1OfTransient.hxx>
b6d587e3 33#include <TColStd_SequenceOfAsciiString.hxx>
900f7229 34#include <TColStd_HSequenceOfAsciiString.hxx>
b6d587e3 35#include <TColStd_MapOfTransient.hxx>
7fd59977 36#include <OSD_Timer.hxx>
37#include <Geom_Axis2Placement.hxx>
38#include <Geom_Axis1Placement.hxx>
39#include <gp_Trsf.hxx>
40#include <TopExp_Explorer.hxx>
41#include <BRepAdaptor_Curve.hxx>
42#include <StdSelect_ShapeTypeFilter.hxx>
43#include <AIS.hxx>
ad3217cd 44#include <AIS_ColoredShape.hxx>
7fd59977 45#include <AIS_InteractiveObject.hxx>
46#include <AIS_Trihedron.hxx>
47#include <AIS_Axis.hxx>
48#include <AIS_Relation.hxx>
49#include <AIS_TypeFilter.hxx>
50#include <AIS_SignatureFilter.hxx>
cb78155f 51#include <AIS_LocalContext.hxx>
7fd59977 52#include <AIS_ListOfInteractive.hxx>
53#include <AIS_ListIteratorOfListOfInteractive.hxx>
99c56d44 54#include <Aspect_InteriorStyle.hxx>
34db9c00 55#include <Aspect_Window.hxx>
99c56d44 56#include <Graphic3d_AspectFillArea3d.hxx>
1c88cbaf 57#include <Graphic3d_AspectLine3d.hxx>
a1954302 58#include <Graphic3d_CStructure.hxx>
392ac980 59#include <Graphic3d_TextureRoot.hxx>
692613e5 60#include <Image_AlienPixMap.hxx>
6262338c 61#include <Prs3d_Drawer.hxx>
99c56d44 62#include <Prs3d_ShadingAspect.hxx>
1c88cbaf 63#include <Prs3d_IsoAspect.hxx>
6262338c 64#include <Prs3d_PointAspect.hxx>
8e7c8ccf 65#include <Select3D_SensitiveWire.hxx>
66#include <SelectMgr_EntityOwner.hxx>
67#include <StdSelect_BRepOwner.hxx>
68#include <StdSelect_ViewerSelector3d.hxx>
cb78155f 69#include <TopTools_MapOfShape.hxx>
4e18052b 70#include <ViewerTest_AutoUpdater.hxx>
7fd59977 71
7fd59977 72#include <stdio.h>
7fd59977 73
74#include <Draw_Interpretor.hxx>
75#include <TCollection_AsciiString.hxx>
76#include <Draw_PluginMacro.hxx>
7fd59977 77
78// avoid warnings on 'extern "C"' functions returning C++ classes
79#ifdef WNT
80#define _CRT_SECURE_NO_DEPRECATE
81#pragma warning(4:4190)
82#pragma warning (disable:4996)
83#endif
84
7fd59977 85extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
86
7fd59977 87#include <Quantity_Color.hxx>
88#include <Quantity_NameOfColor.hxx>
89
90#include <Graphic3d_NameOfMaterial.hxx>
91
6262338c 92#define DEFAULT_COLOR Quantity_NOC_GOLDENROD
93#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
94#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
7fd59977 95
792c785c 96//=======================================================================
97//function : GetColorFromName
98//purpose : get the Quantity_NameOfColor from a string
99//=======================================================================
7fd59977 100
792c785c 101Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
102{
8316c618 103 Quantity_NameOfColor aColor = DEFAULT_COLOR;
104 Quantity_Color::ColorFromName (theName, aColor);
105 return aColor;
7fd59977 106}
107
536d98e2 108//=======================================================================
109//function : ParseColor
110//purpose :
111//=======================================================================
112
113Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb,
114 const char** theArgVec,
115 Quantity_Color& theColor)
116{
117 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
118 if (theArgNb >= 1
119 && Quantity_Color::ColorFromName (theArgVec[0], aColor))
120 {
121 theColor = aColor;
122 return 1;
123 }
124 else if (theArgNb >= 3)
125 {
126 const TCollection_AsciiString anRgbStr[3] =
127 {
128 theArgVec[0],
129 theArgVec[1],
130 theArgVec[2]
131 };
132 if (!anRgbStr[0].IsRealValue()
133 || !anRgbStr[1].IsRealValue()
134 || !anRgbStr[2].IsRealValue())
135 {
136 return 0;
137 }
138
139 Graphic3d_Vec4d anRgb;
140 anRgb.x() = anRgbStr[0].RealValue();
141 anRgb.y() = anRgbStr[1].RealValue();
142 anRgb.z() = anRgbStr[2].RealValue();
143 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
144 || anRgb.y() < 0.0 || anRgb.y() > 1.0
145 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
146 {
147 std::cout << "Error: RGB color values should be within range 0..1!\n";
148 return 0;
149 }
150
151 theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
152 return 3;
153 }
154
155 return 0;
156}
157
a5565a3c 158//=======================================================================
159//function : ParseOnOff
160//purpose :
161//=======================================================================
162Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg,
163 Standard_Boolean& theIsOn)
164{
165 TCollection_AsciiString aFlag(theArg);
166 aFlag.LowerCase();
167 if (aFlag == "on"
168 || aFlag == "1")
169 {
170 theIsOn = Standard_True;
171 return Standard_True;
172 }
173 else if (aFlag == "off"
174 || aFlag == "0")
175 {
176 theIsOn = Standard_False;
177 return Standard_True;
178 }
179 return Standard_False;
180}
181
7fd59977 182//=======================================================================
183//function : GetTypeNames
184//purpose :
185//=======================================================================
186static const char** GetTypeNames()
187{
188 static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane",
189 "Shape","ConnectedShape","MultiConn.Shape",
190 "ConnectedInter.","MultiConn.",
191 "Constraint","Dimension"};
192 static const char** ThePointer = names;
193 return ThePointer;
194}
195
196//=======================================================================
197//function : GetTypeAndSignfromString
198//purpose :
199//=======================================================================
200void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign)
201{
202 const char ** thefullnames = GetTypeNames();
203 Standard_Integer index(-1);
204
205 for(Standard_Integer i=0;i<=13 && index==-1;i++)
206 if(!strcasecmp(name,thefullnames[i]))
207 index = i;
208
209 if(index ==-1){
210 TheType = AIS_KOI_None;
211 TheSign = -1;
212 return;
213 }
214
215 if(index<=6){
216 TheType = AIS_KOI_Datum;
217 TheSign = index+1;
218 }
219 else if (index <=9){
220 TheType = AIS_KOI_Shape;
221 TheSign = index-7;
222 }
223 else if(index<=11){
224 TheType = AIS_KOI_Object;
225 TheSign = index-10;
226 }
227 else{
228 TheType = AIS_KOI_Relation;
229 TheSign = index-12;
230 }
231
232}
233
234
235
236#include <string.h>
237#include <Draw_Interpretor.hxx>
238#include <Draw.hxx>
239#include <Draw_Appli.hxx>
240#include <DBRep.hxx>
241
242
243#include <TCollection_AsciiString.hxx>
244#include <V3d_Viewer.hxx>
245#include <V3d_View.hxx>
246#include <V3d.hxx>
247
248#include <AIS_InteractiveContext.hxx>
249#include <AIS_Shape.hxx>
250#include <AIS_TexturedShape.hxx>
251#include <AIS_DisplayMode.hxx>
252#include <TColStd_MapOfInteger.hxx>
253#include <AIS_MapOfInteractive.hxx>
254#include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
255#include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
256#include <ViewerTest_EventManager.hxx>
257
258#include <TopoDS_Solid.hxx>
259#include <BRepTools.hxx>
260#include <BRep_Builder.hxx>
261#include <TopAbs_ShapeEnum.hxx>
262
263#include <TopoDS.hxx>
264#include <BRep_Tool.hxx>
265
266
267#include <Draw_Window.hxx>
268#include <AIS_ListIteratorOfListOfInteractive.hxx>
269#include <AIS_ListOfInteractive.hxx>
270#include <AIS_DisplayMode.hxx>
271#include <TopTools_ListOfShape.hxx>
272#include <BRepOffsetAPI_MakeThickSolid.hxx>
273#include <BRepOffset.hxx>
274
7fd59977 275//==============================================================================
276// VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES
277//==============================================================================
278Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){
279 static ViewerTest_DoubleMapOfInteractiveAndName TheMap;
280 return TheMap;
281}
282
29e2c6d2 283//=======================================================================
284//function : Display
285//purpose :
286//=======================================================================
287Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName,
288 const Handle(AIS_InteractiveObject)& theObject,
289 const Standard_Boolean theToUpdate,
290 const Standard_Boolean theReplaceIfExists)
9558a876
A
291{
292 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
29e2c6d2 293 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
294 if (aCtx.IsNull())
9558a876 295 {
29e2c6d2 296 std::cout << "Error: AIS context is not available.\n";
9558a876
A
297 return Standard_False;
298 }
299
300 if (aMap.IsBound2 (theName))
301 {
302 if (!theReplaceIfExists)
303 {
29e2c6d2 304 std::cout << "Error: other interactive object has been already registered with name: " << theName << ".\n"
9558a876
A
305 << "Please use another name.\n";
306 return Standard_False;
307 }
308
29e2c6d2 309 Handle(AIS_InteractiveObject) anOldObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName));
9558a876 310 if (!anOldObj.IsNull())
29e2c6d2 311 {
312 aCtx->Remove (anOldObj, Standard_True);
313 }
9558a876
A
314 aMap.UnBind2 (theName);
315 }
316
29e2c6d2 317 if (theObject.IsNull())
208e6839 318 {
29e2c6d2 319 // object with specified name has been already unbound
208e6839 320 return Standard_True;
321 }
322
29e2c6d2 323 // unbind AIS object if it was bound with another name
324 aMap.UnBind1 (theObject);
9558a876
A
325
326 // can be registered without rebinding
29e2c6d2 327 aMap.Bind (theObject, theName);
328 aCtx->Display (theObject, theToUpdate);
9558a876
A
329 return Standard_True;
330}
331
29e2c6d2 332//! Alias for ViewerTest::Display(), compatibility with old code.
333Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
334 const Handle(AIS_InteractiveObject)& theObject,
335 Standard_Boolean theReplaceIfExists = Standard_True)
336{
337 return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
338}
339
7fd59977 340static TColStd_MapOfInteger theactivatedmodes(8);
341static TColStd_ListOfTransient theEventMgrs;
342
d09dda09 343static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
7fd59977 344 const Handle(AIS_InteractiveContext)& Ctx)
345{
346 theEventMgrs.Clear();
347 theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
348}
349
24de79c3 350static Handle(V3d_View)& a3DView()
351{
7fd59977 352 static Handle(V3d_View) Viou;
353 return Viou;
354}
355
24de79c3 356
7fd59977 357Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){
358 static Handle(AIS_InteractiveContext) aContext;
359 return aContext;
360}
361
24de79c3 362const Handle(V3d_View)& ViewerTest::CurrentView()
7fd59977 363{
364 return a3DView();
365}
366void ViewerTest::CurrentView(const Handle(V3d_View)& V)
367{
368 a3DView() = V;
369}
370
24de79c3 371const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext()
7fd59977 372{
373 return TheAISContext();
374}
375
376void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx)
377{
378 TheAISContext() = aCtx;
379 ViewerTest::ResetEventManager();
380}
381
382Handle(V3d_Viewer) ViewerTest::GetViewerFromContext()
383{
4952a30a 384 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 385}
386
387Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext()
388{
4952a30a 389 return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)();
7fd59977 390}
391
392
393void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){
394 theEventMgrs.Prepend(EM);
395}
396
397void ViewerTest::UnsetEventManager()
398{
399 theEventMgrs.RemoveFirst();
400}
401
402
403void ViewerTest::ResetEventManager()
404{
d09dda09 405 const Handle(V3d_View) aView = ViewerTest::CurrentView();
7fd59977 406 VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
407}
408
409Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
410{
411 Handle(ViewerTest_EventManager) EM;
412 if(theEventMgrs.IsEmpty()) return EM;
413 Handle(Standard_Transient) Tr = theEventMgrs.First();
c5f3a425 414 EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
7fd59977 415 return EM;
416}
417
7fd59977 418//=======================================================================
34db9c00 419//function : Get Context and active view
7fd59977 420//purpose :
421//=======================================================================
34db9c00 422static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx,
423 Handle(V3d_View)& theView)
7fd59977 424{
34db9c00 425 theCtx = ViewerTest::GetAISContext();
426 theView = ViewerTest::CurrentView();
427 if (theCtx.IsNull()
428 || theView.IsNull())
7fd59977 429 {
34db9c00 430 std::cout << "Error: cannot find an active view!\n";
431 return Standard_False;
7fd59977 432 }
34db9c00 433 return Standard_True;
7fd59977 434}
435
7fd59977 436//==============================================================================
437//function : GetShapeFromName
438//purpose : Compute an Shape from a draw variable or a file name
439//==============================================================================
440
441static TopoDS_Shape GetShapeFromName(const char* name)
442{
443 TopoDS_Shape S = DBRep::Get(name);
444
445 if ( S.IsNull() ) {
446 BRep_Builder aBuilder;
447 BRepTools::Read( S, name, aBuilder);
448 }
449
450 return S;
451}
4e18e72a 452
7fd59977 453//==============================================================================
454//function : GetAISShapeFromName
455//purpose : Compute an AIS_Shape from a draw variable or a file name
456//==============================================================================
457Handle(AIS_Shape) GetAISShapeFromName(const char* name)
458{
459 Handle(AIS_Shape) retsh;
460
461 if(GetMapOfAIS().IsBound2(name)){
462 const Handle(AIS_InteractiveObject) IO =
463 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
464 if (!IO.IsNull()) {
eafb234b 465 if(IO->Type()==AIS_KOI_Shape) {
7fd59977 466 if(IO->Signature()==0){
c5f3a425 467 retsh = Handle(AIS_Shape)::DownCast (IO);
7fd59977 468 }
469 else
470 cout << "an Object which is not an AIS_Shape "
471 "already has this name!!!"<<endl;
eafb234b 472 }
7fd59977 473 }
474 return retsh;
475 }
476
477
478 TopoDS_Shape S = GetShapeFromName(name);
479 if ( !S.IsNull() ) {
480 retsh = new AIS_Shape(S);
481 }
482 return retsh;
483}
484
485
486//==============================================================================
487//function : Clear
488//purpose : Remove all the object from the viewer
489//==============================================================================
490void ViewerTest::Clear()
491{
492 if ( !a3DView().IsNull() ) {
493 if (TheAISContext()->HasOpenedContext())
494 TheAISContext()->CloseLocalContext();
495 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS());
496 while ( it.More() ) {
497 cout << "Remove " << it.Key2() << endl;
d09dda09 498 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1());
499 TheAISContext()->Remove(anObj,Standard_False);
7fd59977 500 it.Next();
501 }
f751596e 502 TheAISContext()->RebuildSelectionStructs();
7fd59977 503 TheAISContext()->UpdateCurrentViewer();
7fd59977 504 GetMapOfAIS().Clear();
505 }
506}
507
508//==============================================================================
509//function : StandardModesActivation
510//purpose : Activate a selection mode, vertex, edge, wire ..., in a local
511// Context
512//==============================================================================
513void ViewerTest::StandardModeActivation(const Standard_Integer mode )
514{
515 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
516 if(mode==0) {
517 if (TheAISContext()->HasOpenedContext())
518 aContext->CloseLocalContext();
519 } else {
520
521 if(!aContext->HasOpenedContext()) {
522 // To unhilight the preselected object
c3282ec1 523 aContext->UnhilightSelected(Standard_False);
7fd59977 524 // Open a local Context in order to be able to select subshape from
525 // the selected shape if any or for all if there is no selection
c3282ec1 526 if (!aContext->FirstSelectedObject().IsNull()){
7fd59977 527 aContext->OpenLocalContext(Standard_False);
528
c3282ec1 529 for(aContext->InitSelected();aContext->MoreSelected();aContext->NextSelected()){
530 aContext->Load( aContext->SelectedInteractive(),-1,Standard_True);
7fd59977 531 }
532 }
533 else
534 aContext->OpenLocalContext();
535 }
536
537 const char *cmode="???";
538
539 switch (mode) {
540 case 0: cmode = "Shape"; break;
541 case 1: cmode = "Vertex"; break;
542 case 2: cmode = "Edge"; break;
543 case 3: cmode = "Wire"; break;
544 case 4: cmode = "Face"; break;
545 case 5: cmode = "Shell"; break;
546 case 6: cmode = "Solid"; break;
4754e164 547 case 7: cmode = "Compsolid"; break;
548 case 8: cmode = "Compound"; break;
7fd59977 549 }
550
551 if(theactivatedmodes.Contains(mode))
552 { // Desactivate
553 aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode));
554 theactivatedmodes.Remove(mode);
555 cout<<"Mode "<< cmode <<" OFF"<<endl;
556 }
557 else
558 { // Activate
559 aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode));
560 theactivatedmodes.Add(mode);
561 cout<<"Mode "<< cmode << " ON" << endl;
562 }
563 }
564}
565
1c88cbaf 566//==============================================================================
567//function : CopyIsoAspect
568//purpose : Returns copy Prs3d_IsoAspect with new number of isolines.
569//==============================================================================
570static Handle(Prs3d_IsoAspect) CopyIsoAspect
571 (const Handle(Prs3d_IsoAspect) &theIsoAspect,
572 const Standard_Integer theNbIsos)
573{
574 Quantity_Color aColor;
575 Aspect_TypeOfLine aType;
576 Standard_Real aWidth;
577
578 theIsoAspect->Aspect()->Values(aColor, aType, aWidth);
579
580 Handle(Prs3d_IsoAspect) aResult =
581 new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos);
582
583 return aResult;
584}
585
586//==============================================================================
587//function : visos
588//purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag
589//Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]
590//==============================================================================
591static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
592{
593 if (TheAISContext().IsNull()) {
594 di << argv[0] << " Call 'vinit' before!\n";
595 return 1;
596 }
597
598 if (argc <= 1) {
599 di << "Current number of isos : " <<
600 TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " <<
601 TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n";
602 di << "IsoOnPlane mode is " <<
603 (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n";
5ad8c033 604 di << "IsoOnTriangulation mode is " <<
605 (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n";
1c88cbaf 606 return 0;
607 }
608
609 Standard_Integer aLastInd = argc - 1;
610 Standard_Boolean isChanged = Standard_False;
1d47d8d0 611 Standard_Integer aNbUIsos = 0;
612 Standard_Integer aNbVIsos = 0;
1c88cbaf 613
614 if (aLastInd >= 3) {
615 Standard_Boolean isIsoOnPlane = Standard_False;
616
617 if (strcmp(argv[aLastInd], "1") == 0) {
618 isIsoOnPlane = Standard_True;
619 isChanged = Standard_True;
620 } else if (strcmp(argv[aLastInd], "0") == 0) {
621 isIsoOnPlane = Standard_False;
622 isChanged = Standard_True;
623 }
624
625 if (isChanged) {
626 aNbVIsos = Draw::Atoi(argv[aLastInd - 1]);
627 aNbUIsos = Draw::Atoi(argv[aLastInd - 2]);
628 aLastInd -= 3;
629
630 di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n";
631 di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n";
632
633 TheAISContext()->IsoOnPlane(isIsoOnPlane);
634
635 if (aLastInd == 0) {
636 // If there are no shapes provided set the default numbers.
637 TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU);
638 TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV);
639 }
640 }
641 }
642
643 Standard_Integer i;
644
645 for (i = 1; i <= aLastInd; i++) {
646 TCollection_AsciiString name(argv[i]);
647 Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name);
648
649 if (IsBound) {
650 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name);
651 if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) {
652 const Handle(AIS_InteractiveObject) aShape =
653 Handle(AIS_InteractiveObject)::DownCast (anObj);
6262338c 654 Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes();
1c88cbaf 655 Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect();
656 Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect();
657
658 if (isChanged) {
659 CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos));
660 CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos));
661 TheAISContext()->SetLocalAttributes
662 (aShape, CurDrawer, Standard_False);
663 TheAISContext()->Redisplay(aShape);
664 } else {
665 di << "Number of isos for " << argv[i] << " : "
666 << aUIso->Number() << " " << aVIso->Number() << "\n";
667 }
668 } else {
669 di << argv[i] << ": Not an AIS interactive object!\n";
670 }
671 } else {
672 di << argv[i] << ": Use 'vdisplay' before\n";
673 }
674 }
675
676 if (isChanged) {
677 TheAISContext()->UpdateCurrentViewer();
678 }
679
680 return 0;
681}
682
34db9c00 683static Standard_Integer VDispSensi (Draw_Interpretor& ,
684 Standard_Integer theArgNb,
685 Standard_CString* )
7fd59977 686{
34db9c00 687 if (theArgNb > 1)
688 {
689 std::cout << "Error: wrong syntax!\n";
690 return 1;
691 }
692
693 Handle(AIS_InteractiveContext) aCtx;
694 Handle(V3d_View) aView;
695 if (!getCtxAndView (aCtx, aView))
696 {
697 return 1;
698 }
699
700 aCtx->DisplayActiveSensitive (aView);
7fd59977 701 return 0;
702
703}
34db9c00 704
705static Standard_Integer VClearSensi (Draw_Interpretor& ,
706 Standard_Integer theArgNb,
707 Standard_CString* )
7fd59977 708{
34db9c00 709 if (theArgNb > 1)
710 {
711 std::cout << "Error: wrong syntax!\n";
712 return 1;
713 }
714
715 Handle(AIS_InteractiveContext) aCtx;
716 Handle(V3d_View) aView;
717 if (!getCtxAndView (aCtx, aView))
718 {
719 return 1;
720 }
721 aCtx->ClearActiveSensitive (aView);
7fd59977 722 return 0;
723}
724
725//==============================================================================
519d35d8 726//function : VDir
7fd59977 727//purpose : To list the displayed object with their attributes
7fd59977 728//==============================================================================
519d35d8 729static int VDir (Draw_Interpretor& theDI,
730 Standard_Integer ,
731 const char** )
732{
733 if (!a3DView().IsNull())
734 {
735 return 0;
7fd59977 736 }
737
519d35d8 738 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
739 anIter.More(); anIter.Next())
740 {
741 theDI << "\t" << anIter.Key2().ToCString() << "\n";
742 }
7fd59977 743 return 0;
744}
745
3c982548 746//==============================================================================
747//function : VSelPrecision
f751596e 748//purpose : To set the selection tolerance value
749//Draw arg : Selection tolerance value (real value determining the width and
750// height of selecting frustum bases). Without arguments the function
751// just prints current tolerance.
3c982548 752//==============================================================================
753static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
754{
f751596e 755 if( argc > 2 )
3c982548 756 {
28ee613b 757 di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
3c982548 758 return 1;
759 }
760
761 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
762 if( aContext.IsNull() )
763 return 1;
764
765 if( argc == 1 )
766 {
f751596e 767 Standard_Real aPixelTolerance = aContext->PixelTolerance();
f751596e 768 di << "Pixel tolerance : " << aPixelTolerance << "\n";
3c982548 769 }
f751596e 770 else if (argc == 2)
3c982548 771 {
28ee613b 772 TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
773 anArg.LowerCase();
774 if (anArg == "-unset")
775 {
3bf9a45f 776 aContext->SetPixelTolerance (-1);
28ee613b 777 }
778 else
779 {
3bf9a45f 780 aContext->SetPixelTolerance (anArg.IntegerValue());
28ee613b 781 }
3c982548 782 }
f751596e 783
3c982548 784 return 0;
785}
786
f978241f 787//! Auxiliary enumeration
788enum ViewerTest_StereoPair
789{
790 ViewerTest_SP_Single,
791 ViewerTest_SP_SideBySide,
792 ViewerTest_SP_OverUnder
793};
794
7fd59977 795//==============================================================================
796//function : VDump
797//purpose : To dump the active view snapshot to image file
7fd59977 798//==============================================================================
34db9c00 799static Standard_Integer VDump (Draw_Interpretor& theDI,
800 Standard_Integer theArgNb,
801 Standard_CString* theArgVec)
7fd59977 802{
34db9c00 803 if (theArgNb < 2)
7fd59977 804 {
34db9c00 805 std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n";
7fd59977 806 return 1;
807 }
808
34db9c00 809 Standard_Integer anArgIter = 1;
810 Standard_CString aFilePath = theArgVec[anArgIter++];
811 Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB;
812 V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO;
f978241f 813 ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single;
34db9c00 814 Standard_Integer aWidth = 0;
815 Standard_Integer aHeight = 0;
816 for (; anArgIter < theArgNb; ++anArgIter)
7fd59977 817 {
34db9c00 818 TCollection_AsciiString anArg (theArgVec[anArgIter]);
819 anArg.LowerCase();
f978241f 820 if (anArg == "-buffer")
7fd59977 821 {
f978241f 822 if (++anArgIter >= theArgNb)
823 {
824 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
825 return 1;
826 }
827
828 TCollection_AsciiString aBufArg (theArgVec[anArgIter]);
829 aBufArg.LowerCase();
830 if (aBufArg == "rgba")
831 {
832 aBufferType = Graphic3d_BT_RGBA;
833 }
834 else if (aBufArg == "rgb")
835 {
836 aBufferType = Graphic3d_BT_RGB;
837 }
838 else if (aBufArg == "depth")
839 {
840 aBufferType = Graphic3d_BT_Depth;
841 }
842 else
843 {
844 std::cout << "Error: unknown buffer '" << aBufArg << "'\n";
845 return 1;
846 }
7fd59977 847 }
f978241f 848 else if (anArg == "-stereo")
7fd59977 849 {
f978241f 850 if (++anArgIter >= theArgNb)
851 {
852 std::cout << "Error: wrong syntax at '" << anArg << "'\n";
853 return 1;
854 }
855
856 TCollection_AsciiString aStereoArg (theArgVec[anArgIter]);
857 aStereoArg.LowerCase();
858 if (aStereoArg == "l"
859 || aStereoArg == "left")
860 {
861 aStereoOpts = V3d_SDO_LEFT_EYE;
862 }
863 else if (aStereoArg == "r"
864 || aStereoArg == "right")
865 {
866 aStereoOpts = V3d_SDO_RIGHT_EYE;
867 }
868 else if (aStereoArg == "mono")
869 {
870 aStereoOpts = V3d_SDO_MONO;
871 }
872 else if (aStereoArg == "blended"
873 || aStereoArg == "blend"
874 || aStereoArg == "stereo")
875 {
876 aStereoOpts = V3d_SDO_BLENDED;
877 }
878 else if (aStereoArg == "sbs"
879 || aStereoArg == "sidebyside")
880 {
881 aStereoPair = ViewerTest_SP_SideBySide;
882 }
883 else if (aStereoArg == "ou"
884 || aStereoArg == "overunder")
885 {
886 aStereoPair = ViewerTest_SP_OverUnder;
887 }
888 else
889 {
890 std::cout << "Error: unknown stereo format '" << aStereoArg << "'\n";
891 return 1;
892 }
7fd59977 893 }
f978241f 894 else if (anArg == "-rgba"
895 || anArg == "rgba")
34db9c00 896 {
f978241f 897 aBufferType = Graphic3d_BT_RGBA;
34db9c00 898 }
f978241f 899 else if (anArg == "-rgb"
900 || anArg == "rgb")
34db9c00 901 {
f978241f 902 aBufferType = Graphic3d_BT_RGB;
34db9c00 903 }
f978241f 904 else if (anArg == "-depth"
905 || anArg == "depth")
34db9c00 906 {
f978241f 907 aBufferType = Graphic3d_BT_Depth;
34db9c00 908 }
f978241f 909
910 else if (anArg == "-width"
911 || anArg == "width"
912 || anArg == "sizex")
34db9c00 913 {
f978241f 914 if (aWidth != 0)
34db9c00 915 {
916 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
917 return 1;
918 }
919 else if (++anArgIter >= theArgNb)
920 {
921 std::cout << "Error: integer value is expected right after 'width'\n";
922 return 1;
923 }
924 aWidth = Draw::Atoi (theArgVec[anArgIter]);
925 }
f978241f 926 else if (anArg == "-height"
927 || anArg == "height"
928 || anArg == "-sizey")
34db9c00 929 {
930 if (aHeight != 0)
931 {
932 std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n";
933 return 1;
934 }
34db9c00 935 else if (++anArgIter >= theArgNb)
936 {
f978241f 937 std::cout << "Error: integer value is expected right after 'height'\n";
34db9c00 938 return 1;
939 }
34db9c00 940 aHeight = Draw::Atoi (theArgVec[anArgIter]);
941 }
942 else
943 {
944 std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n";
945 return 1;
946 }
7fd59977 947 }
34db9c00 948 if ((aWidth <= 0 && aHeight > 0)
949 || (aWidth > 0 && aHeight <= 0))
7fd59977 950 {
34db9c00 951 std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n";
85e096c3 952 return 1;
953 }
954
34db9c00 955 Handle(V3d_View) aView = ViewerTest::CurrentView();
956 if (aView.IsNull())
85e096c3 957 {
34db9c00 958 std::cout << "Error: cannot find an active view!\n";
959 return 1;
7fd59977 960 }
85e096c3 961
34db9c00 962 if (aWidth <= 0 || aHeight <= 0)
b5ac8292 963 {
f978241f 964 aView->Window()->Size (aWidth, aHeight);
965 }
966
967 Image_AlienPixMap aPixMap;
968
969 bool isBigEndian = Image_PixMap::IsBigEndianHost();
970 Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
971 switch (aBufferType)
972 {
973 case Graphic3d_BT_RGB: aFormat = isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR; break;
974 case Graphic3d_BT_RGBA: aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
975 case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
976 }
977
978 switch (aStereoPair)
979 {
980 case ViewerTest_SP_Single:
b5ac8292 981 {
f978241f 982 if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts))
983 {
984 theDI << "Fail: view dump failed!\n";
985 return 0;
986 }
987 else if (aPixMap.SizeX() != Standard_Size(aWidth)
988 || aPixMap.SizeY() != Standard_Size(aHeight))
989 {
990 theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY()
991 << " are lesser than requested " << aWidth << "x" << aHeight << "\n";
992 }
993 break;
b5ac8292 994 }
f978241f 995 case ViewerTest_SP_SideBySide:
b5ac8292 996 {
f978241f 997 if (!aPixMap.InitZero (aFormat, aWidth * 2, aHeight))
998 {
999 theDI << "Fail: not enough memory for image allocation!\n";
1000 return 0;
1001 }
1002
1003 Image_PixMap aPixMapL, aPixMapR;
1004 aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(),
1005 aWidth, aHeight, aPixMap.SizeRowBytes());
1006 aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aWidth,
1007 aWidth, aHeight, aPixMap.SizeRowBytes());
1008 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1009 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE)
1010 )
34db9c00 1011 {
1012 theDI << "Fail: view dump failed!\n";
f978241f 1013 return 0;
34db9c00 1014 }
f978241f 1015 break;
b5ac8292 1016 }
f978241f 1017 case ViewerTest_SP_OverUnder:
1018 {
1019 if (!aPixMap.InitZero (aFormat, aWidth, aHeight * 2))
1020 {
1021 theDI << "Fail: not enough memory for image allocation!\n";
1022 return 0;
1023 }
b5ac8292 1024
f978241f 1025 Image_PixMap aPixMapL, aPixMapR;
1026 aPixMapL.InitWrapper (aFormat, aPixMap.ChangeData(),
1027 aWidth, aHeight, aPixMap.SizeRowBytes());
1028 aPixMapR.InitWrapper (aFormat, aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aHeight,
1029 aWidth, aHeight, aPixMap.SizeRowBytes());
1030 if (!aView->ToPixMap (aPixMapL, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_LEFT_EYE)
1031 || !aView->ToPixMap (aPixMapR, aWidth, aHeight, aBufferType, Standard_True, V3d_SDO_RIGHT_EYE))
1032 {
1033 theDI << "Fail: view dump failed!\n";
1034 return 0;
1035 }
1036 break;
1037 }
7fd59977 1038 }
85e096c3 1039
34db9c00 1040 if (!aPixMap.Save (aFilePath))
85e096c3 1041 {
34db9c00 1042 theDI << "Fail: image can not be saved!\n";
85e096c3 1043 }
1044 return 0;
7fd59977 1045}
1046
7fd59977 1047//==============================================================================
1048//function : Displays,Erase...
1049//purpose :
1050//Draw arg :
1051//==============================================================================
1052static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO,
1053 const Standard_Integer Mode,
1054 const Standard_Integer TypeOfOperation,
1055 const Standard_Boolean Upd)
1056{
1057 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1058
1059 switch(TypeOfOperation){
1060 case 1:
1061 Ctx->Display(IO,Mode,Upd);
1062 break;
1063 case 2:{
eb4320f2 1064 Ctx->Erase(IO,Upd);
7fd59977 1065 break;
1066 }
1067 case 3:{
1068 if(IO.IsNull())
1069 Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd);
1070 else
1071 Ctx->SetDisplayMode(IO,Mode,Upd);
1072 break;
1073 }
1074 case 4:{
1075 if(IO.IsNull())
1076 Ctx->SetDisplayMode(0,Upd);
1077 else
1078 Ctx->UnsetDisplayMode(IO,Upd);
1079 break;
1080 }
1081 }
1082 return 0;
1083}
1084
1085//=======================================================================
1086//function :
1087//purpose :
1088//=======================================================================
1089static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv)
1090{
1091
1092 TCollection_AsciiString name;
1093 if(argc>3)
1094 return 1;
1095 // display others presentations
1096 Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1:
1097 (strcasecmp(argv[0],"verasemode")==0) ? 2 :
1098 (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 :
1099 (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1;
1100
1101 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
1102
1103 //unset displaymode.. comportement particulier...
1104 if(TypeOfOperation==4){
1105 if(argc==1){
c3282ec1 1106 if(Ctx->NbSelected()==0){
7fd59977 1107 Handle(AIS_InteractiveObject) IO;
1108 VwrTst_DispErase(IO,-1,4,Standard_False);
1109 }
7fd59977 1110 else{
1111 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
c3282ec1 1112 VwrTst_DispErase(Ctx->SelectedInteractive(),-1,4,Standard_False);}
7fd59977 1113 Ctx->UpdateCurrentViewer();
1114 }
1115 else{
1116 Handle(AIS_InteractiveObject) IO;
1117 name = argv[1];
1118 if(GetMapOfAIS().IsBound2(name)){
1119 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1120 if (!IO.IsNull())
1121 VwrTst_DispErase(IO,-1,4,Standard_True);
1122 }
1123 }
1124 }
1125 else if(argc==2){
91322f44 1126 Standard_Integer Dmode = Draw::Atoi(argv[1]);
c3282ec1 1127 if(Ctx->NbSelected()==0 && TypeOfOperation==3){
7fd59977 1128 Handle(AIS_InteractiveObject) IO;
1129 VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True);
1130 }
1131 if(!Ctx->HasOpenedContext()){
1132 // set/unset display mode sur le Contexte...
c3282ec1 1133 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){
1134 VwrTst_DispErase(Ctx->SelectedInteractive(),Dmode,TypeOfOperation,Standard_False);
7fd59977 1135 }
1136 Ctx->UpdateCurrentViewer();
1137 }
1138 else{
1139 for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected())
c3282ec1 1140 Ctx->Display(Ctx->SelectedInteractive(),Dmode);
7fd59977 1141 }
1142 }
1143 else{
1144 Handle(AIS_InteractiveObject) IO;
1145 name = argv[1];
1146 if(GetMapOfAIS().IsBound2(name))
1147 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
1148 if (!IO.IsNull())
91322f44 1149 VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True);
7fd59977 1150 }
1151 return 0;
1152}
1153
1154
1155//=======================================================================
1156//function :
1157//purpose :
1158//=======================================================================
1159static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1160{
1161 if(argc==1) return 1;
91322f44 1162 Standard_Integer On = Draw::Atoi(argv[1]);
7fd59977 1163 const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
1164
c3282ec1 1165 if(argc==2)
1166 {
1167 TCollection_AsciiString isOnOff = On == 1 ? "on" : "off";
1168 di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n";
1169 for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected())
1170 {
1171 if(On==1)
1172 {
1173 Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1174 }
c3282ec1 1175 else
1176 {
1177 Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False);
7fd59977 1178 }
1179 }
c3282ec1 1180
7fd59977 1181 Ctx->UpdateCurrentViewer();
1182 }
1183 else {
1184 Handle(AIS_InteractiveObject) IO;
1185 TCollection_AsciiString name = argv[2];
1186 if(GetMapOfAIS().IsBound2(name)){
1187 IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
eafb234b 1188 if (!IO.IsNull()) {
7fd59977 1189 if(On==1)
1190 Ctx->SubIntensityOn(IO);
1191 else
1192 Ctx->SubIntensityOff(IO);
eafb234b 1193 }
7fd59977 1194 }
1195 else return 1;
1196 }
1197 return 0;
7fd59977 1198}
7fd59977 1199
ad3217cd 1200//! Auxiliary class to iterate presentations from different collections.
1201class ViewTest_PrsIter
1202{
1203public:
7fd59977 1204
ad3217cd 1205 //! Create and initialize iterator object.
1206 ViewTest_PrsIter (const TCollection_AsciiString& theName)
1207 : mySource (IterSource_All)
1208 {
1209 NCollection_Sequence<TCollection_AsciiString> aNames;
1210 if (!theName.IsEmpty())
1211 aNames.Append (theName);
1212 Init (aNames);
7fd59977 1213 }
ad3217cd 1214
1215 //! Create and initialize iterator object.
1216 ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1217 : mySource (IterSource_All)
1218 {
1219 Init (theNames);
7fd59977 1220 }
1221
ad3217cd 1222 //! Initialize the iterator.
1223 void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames)
1224 {
1225 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
1226 mySeq = theNames;
1227 mySelIter.Nullify();
1228 myCurrent.Nullify();
1229 myCurrentTrs.Nullify();
1230 if (!mySeq.IsEmpty())
1231 {
1232 mySource = IterSource_List;
1233 mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq);
7fd59977 1234 }
c3282ec1 1235 else if (aCtx->NbSelected() > 0)
ad3217cd 1236 {
1237 mySource = IterSource_Selected;
1238 mySelIter = aCtx;
c3282ec1 1239 mySelIter->InitSelected();
ad3217cd 1240 }
1241 else
1242 {
1243 mySource = IterSource_All;
1244 myMapIter.Initialize (GetMapOfAIS());
1245 }
1246 initCurrent();
1247 }
7fd59977 1248
ad3217cd 1249 const TCollection_AsciiString& CurrentName() const
1250 {
1251 return myCurrentName;
1252 }
7fd59977 1253
ad3217cd 1254 const Handle(AIS_InteractiveObject)& Current() const
1255 {
1256 return myCurrent;
1257 }
7fd59977 1258
ad3217cd 1259 const Handle(Standard_Transient)& CurrentTrs() const
1260 {
1261 return myCurrentTrs;
1262 }
1263
1264 //! @return true if iterator points to valid object within collection
1265 Standard_Boolean More() const
1266 {
1267 switch (mySource)
1268 {
1269 case IterSource_All: return myMapIter.More();
1270 case IterSource_List: return mySeqIter.More();
c3282ec1 1271 case IterSource_Selected: return mySelIter->MoreSelected();
ad3217cd 1272 }
1273 return Standard_False;
1274 }
1275
1276 //! Go to the next item.
1277 void Next()
1278 {
1279 myCurrentName.Clear();
1280 myCurrentTrs.Nullify();
1281 myCurrent.Nullify();
1282 switch (mySource)
1283 {
1284 case IterSource_All:
1285 {
1286 myMapIter.Next();
1287 break;
1288 }
1289 case IterSource_List:
1290 {
1291 mySeqIter.Next();
1292 break;
1293 }
1294 case IterSource_Selected:
1295 {
c3282ec1 1296 mySelIter->NextSelected();
ad3217cd 1297 break;
7fd59977 1298 }
1299 }
ad3217cd 1300 initCurrent();
1301 }
7fd59977 1302
ad3217cd 1303private:
7fd59977 1304
ad3217cd 1305 void initCurrent()
1306 {
1307 switch (mySource)
1308 {
1309 case IterSource_All:
7fd59977 1310 {
ad3217cd 1311 if (myMapIter.More())
1312 {
1313 myCurrentName = myMapIter.Key2();
1314 myCurrentTrs = myMapIter.Key1();
1315 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
eafb234b 1316 }
ad3217cd 1317 break;
1318 }
1319 case IterSource_List:
1320 {
1321 if (mySeqIter.More())
1322 {
1323 if (!GetMapOfAIS().IsBound2 (mySeqIter.Value()))
1324 {
1325 std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n";
1326 return;
1327 }
1328 myCurrentName = mySeqIter.Value();
1329 myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value());
1330 myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs);
1331 }
1332 break;
1333 }
1334 case IterSource_Selected:
1335 {
c3282ec1 1336 if (mySelIter->MoreSelected())
ad3217cd 1337 {
c3282ec1 1338 myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive());
1339 myCurrent = mySelIter->SelectedInteractive();
ad3217cd 1340 }
1341 break;
7fd59977 1342 }
7fd59977 1343 }
1344 }
ad3217cd 1345
1346private:
1347
1348 enum IterSource
1349 {
1350 IterSource_All,
1351 IterSource_List,
1352 IterSource_Selected
1353 };
1354
1355private:
1356
1357 Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected)
1358 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All)
1359 NCollection_Sequence<TCollection_AsciiString> mySeq;
1360 NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter;
1361
1362 TCollection_AsciiString myCurrentName;//!< current item name
1363 Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object)
1364 Handle(AIS_InteractiveObject) myCurrent; //!< current item
1365
1366 IterSource mySource; //!< iterated collection
1367
1368};
7fd59977 1369
1370//==============================================================================
ad3217cd 1371//function : VInteriorStyle
1372//purpose : sets interior style of the a selected or named or displayed shape
7fd59977 1373//==============================================================================
ad3217cd 1374static int VSetInteriorStyle (Draw_Interpretor& theDI,
1375 Standard_Integer theArgNb,
1376 const char** theArgVec)
7fd59977 1377{
ad3217cd 1378 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1379 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1380 if (aCtx.IsNull())
1381 {
1382 std::cerr << "Error: no active view!\n";
1383 return 1;
1384 }
7fd59977 1385
4e18052b 1386 Standard_Integer anArgIter = 1;
ad3217cd 1387 for (; anArgIter < theArgNb; ++anArgIter)
1388 {
4e18052b 1389 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
ad3217cd 1390 {
1391 break;
1392 }
7fd59977 1393 }
ad3217cd 1394 TCollection_AsciiString aName;
1395 if (theArgNb - anArgIter == 2)
1396 {
1397 aName = theArgVec[anArgIter++];
1398 }
1399 else if (theArgNb - anArgIter != 1)
1400 {
1401 std::cout << "Error: wrong number of arguments! See usage:\n";
1402 theDI.PrintHelp (theArgVec[0]);
1403 return 1;
1404 }
1405 Standard_Integer anInterStyle = Aspect_IS_SOLID;
1406 TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
1407 aStyleArg.LowerCase();
1408 if (aStyleArg == "empty")
1409 {
1410 anInterStyle = 0;
1411 }
1412 else if (aStyleArg == "hollow")
1413 {
1414 anInterStyle = 1;
1415 }
1416 else if (aStyleArg == "hatch")
1417 {
1418 anInterStyle = 2;
1419 }
1420 else if (aStyleArg == "solid")
1421 {
1422 anInterStyle = 3;
1423 }
1424 else if (aStyleArg == "hiddenline")
1425 {
1426 anInterStyle = 4;
1427 }
1428 else
1429 {
1430 anInterStyle = aStyleArg.IntegerValue();
1431 }
1432 if (anInterStyle < Aspect_IS_EMPTY
1433 || anInterStyle > Aspect_IS_HIDDENLINE)
1434 {
1435 std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
1436 << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n";
1437 return 1;
7fd59977 1438 }
1439
ad3217cd 1440 if (!aName.IsEmpty()
1441 && !GetMapOfAIS().IsBound2 (aName))
1442 {
1443 std::cout << "Error: object " << aName << " is not displayed!\n";
1444 return 1;
1445 }
1446
1447 if (aCtx->HasOpenedContext())
1448 {
1449 aCtx->CloseLocalContext();
1450 }
1451 for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next())
1452 {
1453 const Handle(AIS_InteractiveObject)& anIO = anIter.Current();
1454 if (!anIO.IsNull())
1455 {
1456 const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
1457 Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
1458 Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
1459 aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle);
1460 aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
7fd59977 1461 }
ad3217cd 1462 }
ad3217cd 1463 return 0;
1464}
7fd59977 1465
ad3217cd 1466//! Auxiliary structure for VAspects
1467struct ViewerTest_AspectsChangeSet
1468{
5bffb882 1469 Standard_Integer ToSetVisibility;
1470 Standard_Integer Visibility;
1471
ad3217cd 1472 Standard_Integer ToSetColor;
1473 Quantity_Color Color;
1474
1475 Standard_Integer ToSetLineWidth;
1476 Standard_Real LineWidth;
1477
ac116c22 1478 Standard_Integer ToSetTypeOfLine;
1479 Aspect_TypeOfLine TypeOfLine;
1480
ad3217cd 1481 Standard_Integer ToSetTransparency;
1482 Standard_Real Transparency;
1483
1484 Standard_Integer ToSetMaterial;
1485 Graphic3d_NameOfMaterial Material;
1486 TCollection_AsciiString MatName;
1487
1488 NCollection_Sequence<TopoDS_Shape> SubShapes;
1489
6262338c 1490 Standard_Integer ToSetShowFreeBoundary;
1491 Standard_Integer ToSetFreeBoundaryWidth;
1492 Standard_Real FreeBoundaryWidth;
1493 Standard_Integer ToSetFreeBoundaryColor;
1494 Quantity_Color FreeBoundaryColor;
1495
5ad8c033 1496 Standard_Integer ToEnableIsoOnTriangulation;
1497
1498 Standard_Integer ToSetMaxParamValue;
1499 Standard_Real MaxParamValue;
1500
8a1170ad 1501 Standard_Integer ToSetSensitivity;
1502 Standard_Integer SelectionMode;
1503 Standard_Integer Sensitivity;
1504
ad3217cd 1505 //! Empty constructor
1506 ViewerTest_AspectsChangeSet()
5bffb882 1507 : ToSetVisibility (0),
1508 Visibility (1),
1509 ToSetColor (0),
ad3217cd 1510 Color (DEFAULT_COLOR),
1511 ToSetLineWidth (0),
1512 LineWidth (1.0),
ac116c22 1513 ToSetTypeOfLine (0),
1514 TypeOfLine (Aspect_TOL_SOLID),
ad3217cd 1515 ToSetTransparency (0),
1516 Transparency (0.0),
1517 ToSetMaterial (0),
6262338c 1518 Material (Graphic3d_NOM_DEFAULT),
5ad8c033 1519 ToSetShowFreeBoundary (0),
1520 ToSetFreeBoundaryWidth (0),
1521 FreeBoundaryWidth (1.0),
1522 ToSetFreeBoundaryColor (0),
1523 FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR),
1524 ToEnableIsoOnTriangulation (-1),
1525 ToSetMaxParamValue (0),
8a1170ad 1526 MaxParamValue (500000),
1527 ToSetSensitivity (0),
1528 SelectionMode (-1),
1529 Sensitivity (-1) {}
ad3217cd 1530
1531 //! @return true if no changes have been requested
1532 Standard_Boolean IsEmpty() const
1533 {
6262338c 1534 return ToSetVisibility == 0
1535 && ToSetLineWidth == 0
1536 && ToSetTransparency == 0
1537 && ToSetColor == 0
1538 && ToSetMaterial == 0
1539 && ToSetShowFreeBoundary == 0
1540 && ToSetFreeBoundaryColor == 0
5ad8c033 1541 && ToSetFreeBoundaryWidth == 0
8a1170ad 1542 && ToSetMaxParamValue == 0
1543 && ToSetSensitivity == 0;
ad3217cd 1544 }
1545
1546 //! @return true if properties are valid
1547 Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const
1548 {
1549 Standard_Boolean isOk = Standard_True;
5bffb882 1550 if (Visibility != 0 && Visibility != 1)
1551 {
1552 std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n";
1553 isOk = Standard_False;
1554 }
ad3217cd 1555 if (LineWidth <= 0.0
1556 || LineWidth > 10.0)
1557 {
1558 std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n";
1559 isOk = Standard_False;
7fd59977 1560 }
ad3217cd 1561 if (Transparency < 0.0
1562 || Transparency > 1.0)
1563 {
1564 std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n";
1565 isOk = Standard_False;
1566 }
1567 if (theIsSubPart
1568 && ToSetTransparency)
1569 {
1570 std::cout << "Error: the transparency can not be defined for sub-part of object!\n";
1571 isOk = Standard_False;
7fd59977 1572 }
ad3217cd 1573 if (ToSetMaterial == 1
1574 && Material == Graphic3d_NOM_DEFAULT)
1575 {
1576 std::cout << "Error: unknown material " << MatName << ".\n";
1577 isOk = Standard_False;
1578 }
6262338c 1579 if (FreeBoundaryWidth <= 0.0
1580 || FreeBoundaryWidth > 10.0)
1581 {
1582 std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n";
1583 isOk = Standard_False;
1584 }
5ad8c033 1585 if (MaxParamValue < 0.0)
1586 {
1587 std::cout << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")\n";
1588 isOk = Standard_False;
1589 }
8a1170ad 1590 if (Sensitivity <= 0 && ToSetSensitivity)
1591 {
1592 std::cout << "Error: sensitivity parameter value should be positive (specified " << Sensitivity << ")\n";
1593 isOk = Standard_False;
1594 }
ad3217cd 1595 return isOk;
7fd59977 1596 }
7fd59977 1597
ad3217cd 1598};
7fd59977 1599
1600//==============================================================================
ad3217cd 1601//function : VAspects
1602//purpose :
7fd59977 1603//==============================================================================
ad3217cd 1604static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
1605 Standard_Integer theArgNb,
1606 const char** theArgVec)
7fd59977 1607{
ad3217cd 1608 TCollection_AsciiString aCmdName (theArgVec[0]);
1609 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 1610 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
ad3217cd 1611 if (aCtx.IsNull())
1612 {
1613 std::cerr << "Error: no active view!\n";
1614 return 1;
1615 }
7fd59977 1616
4e18052b 1617 Standard_Integer anArgIter = 1;
6262338c 1618 Standard_Boolean isDefaults = Standard_False;
ad3217cd 1619 NCollection_Sequence<TCollection_AsciiString> aNames;
1620 for (; anArgIter < theArgNb; ++anArgIter)
1621 {
1622 TCollection_AsciiString anArg = theArgVec[anArgIter];
4e18052b 1623 if (anUpdateTool.parseRedrawMode (anArg))
ad3217cd 1624 {
1625 continue;
1626 }
1627 else if (!anArg.IsEmpty()
1628 && anArg.Value (1) != '-')
1629 {
1630 aNames.Append (anArg);
1631 }
1632 else
1633 {
6262338c 1634 if (anArg == "-defaults")
1635 {
1636 isDefaults = Standard_True;
1637 ++anArgIter;
1638 }
ad3217cd 1639 break;
1640 }
1641 }
1642
6262338c 1643 if (!aNames.IsEmpty() && isDefaults)
1644 {
1645 std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n";
1646 return 1;
1647 }
1648
ad3217cd 1649 NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges;
1650 aChanges.Append (ViewerTest_AspectsChangeSet());
1651 ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast();
7fd59977 1652
ad3217cd 1653 // parse syntax of legacy commands
1654 if (aCmdName == "vsetwidth")
1655 {
1656 if (aNames.IsEmpty()
1657 || !aNames.Last().IsRealValue())
1658 {
1659 std::cout << "Error: not enough arguments!\n";
1660 return 1;
1661 }
1662 aChangeSet->ToSetLineWidth = 1;
1663 aChangeSet->LineWidth = aNames.Last().RealValue();
1664 aNames.Remove (aNames.Length());
7fd59977 1665 }
ad3217cd 1666 else if (aCmdName == "vunsetwidth")
1667 {
1668 aChangeSet->ToSetLineWidth = -1;
1669 }
1670 else if (aCmdName == "vsetcolor")
1671 {
1672 if (aNames.IsEmpty())
1673 {
1674 std::cout << "Error: not enough arguments!\n";
1675 return 1;
1676 }
1677 aChangeSet->ToSetColor = 1;
8316c618 1678
1679 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1680 Standard_Boolean isOk = Standard_False;
1681 if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
1682 {
1683 aChangeSet->Color = aColor;
1684 aNames.Remove (aNames.Length());
1685 isOk = Standard_True;
1686 }
1687 else if (aNames.Length() >= 3)
1688 {
1689 const TCollection_AsciiString anRgbStr[3] =
1690 {
1691 aNames.Value (aNames.Upper() - 2),
1692 aNames.Value (aNames.Upper() - 1),
1693 aNames.Value (aNames.Upper() - 0)
1694 };
1695 isOk = anRgbStr[0].IsRealValue()
1696 && anRgbStr[1].IsRealValue()
1697 && anRgbStr[2].IsRealValue();
1698 if (isOk)
1699 {
1700 Graphic3d_Vec4d anRgb;
1701 anRgb.x() = anRgbStr[0].RealValue();
1702 anRgb.y() = anRgbStr[1].RealValue();
1703 anRgb.z() = anRgbStr[2].RealValue();
1704 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1705 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1706 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1707 {
1708 std::cout << "Error: RGB color values should be within range 0..1!\n";
1709 return 1;
1710 }
1711 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1712 aNames.Remove (aNames.Length());
1713 aNames.Remove (aNames.Length());
1714 aNames.Remove (aNames.Length());
1715 }
1716 }
1717 if (!isOk)
1718 {
1719 std::cout << "Error: not enough arguments!\n";
1720 return 1;
1721 }
ad3217cd 1722 }
1723 else if (aCmdName == "vunsetcolor")
1724 {
1725 aChangeSet->ToSetColor = -1;
1726 }
1727 else if (aCmdName == "vsettransparency")
1728 {
1729 if (aNames.IsEmpty()
1730 || !aNames.Last().IsRealValue())
1731 {
1732 std::cout << "Error: not enough arguments!\n";
1733 return 1;
1734 }
1735 aChangeSet->ToSetTransparency = 1;
1736 aChangeSet->Transparency = aNames.Last().RealValue();
1737 aNames.Remove (aNames.Length());
1738 }
1739 else if (aCmdName == "vunsettransparency")
1740 {
1741 aChangeSet->ToSetTransparency = -1;
1742 }
1743 else if (aCmdName == "vsetmaterial")
1744 {
1745 if (aNames.IsEmpty())
1746 {
1747 std::cout << "Error: not enough arguments!\n";
1748 return 1;
1749 }
1750 aChangeSet->ToSetMaterial = 1;
1751 aChangeSet->MatName = aNames.Last();
1752 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1753 aNames.Remove (aNames.Length());
1754 }
1755 else if (aCmdName == "vunsetmaterial")
1756 {
1757 aChangeSet->ToSetMaterial = -1;
1758 }
1759 else if (anArgIter >= theArgNb)
1760 {
1761 std::cout << "Error: not enough arguments!\n";
1762 return 1;
7fd59977 1763 }
1764
ad3217cd 1765 if (!aChangeSet->IsEmpty())
1766 {
1767 anArgIter = theArgNb;
1768 }
1769 for (; anArgIter < theArgNb; ++anArgIter)
1770 {
1771 TCollection_AsciiString anArg = theArgVec[anArgIter];
1772 anArg.LowerCase();
1773 if (anArg == "-setwidth"
1774 || anArg == "-setlinewidth")
1775 {
1776 if (++anArgIter >= theArgNb)
1777 {
1778 std::cout << "Error: wrong syntax at " << anArg << "\n";
1779 return 1;
1780 }
1781 aChangeSet->ToSetLineWidth = 1;
1782 aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]);
7fd59977 1783 }
ad3217cd 1784 else if (anArg == "-unsetwidth"
1785 || anArg == "-unsetlinewidth")
1786 {
1787 aChangeSet->ToSetLineWidth = -1;
1788 aChangeSet->LineWidth = 1.0;
1789 }
1790 else if (anArg == "-settransp"
0ae61cf3 1791 || anArg == "-settransparency")
ad3217cd 1792 {
1793 if (++anArgIter >= theArgNb)
1794 {
1795 std::cout << "Error: wrong syntax at " << anArg << "\n";
1796 return 1;
1797 }
1798 aChangeSet->ToSetTransparency = 1;
1799 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1800 if (aChangeSet->Transparency >= 0.0
1801 && aChangeSet->Transparency <= Precision::Confusion())
1802 {
1803 aChangeSet->ToSetTransparency = -1;
1804 aChangeSet->Transparency = 0.0;
eafb234b 1805 }
7fd59977 1806 }
5bffb882 1807 else if (anArg == "-setvis"
1808 || anArg == "-setvisibility")
1809 {
1810 if (++anArgIter >= theArgNb)
1811 {
1812 std::cout << "Error: wrong syntax at " << anArg << "\n";
1813 return 1;
1814 }
1815
1816 aChangeSet->ToSetVisibility = 1;
1817 aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]);
1818 }
ad3217cd 1819 else if (anArg == "-setalpha")
1820 {
1821 if (++anArgIter >= theArgNb)
7fd59977 1822 {
ad3217cd 1823 std::cout << "Error: wrong syntax at " << anArg << "\n";
1824 return 1;
1825 }
1826 aChangeSet->ToSetTransparency = 1;
1827 aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]);
1828 if (aChangeSet->Transparency < 0.0
1829 || aChangeSet->Transparency > 1.0)
1830 {
1831 std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n";
1832 return 1;
1833 }
1834 aChangeSet->Transparency = 1.0 - aChangeSet->Transparency;
1835 if (aChangeSet->Transparency >= 0.0
1836 && aChangeSet->Transparency <= Precision::Confusion())
1837 {
1838 aChangeSet->ToSetTransparency = -1;
1839 aChangeSet->Transparency = 0.0;
7fd59977 1840 }
7fd59977 1841 }
ad3217cd 1842 else if (anArg == "-unsettransp"
0ae61cf3 1843 || anArg == "-unsettransparency"
ad3217cd 1844 || anArg == "-unsetalpha"
1845 || anArg == "-opaque")
1846 {
1847 aChangeSet->ToSetTransparency = -1;
1848 aChangeSet->Transparency = 0.0;
1849 }
1850 else if (anArg == "-setcolor")
1851 {
8316c618 1852 Standard_Integer aNbComps = 0;
1853 Standard_Integer aCompIter = anArgIter + 1;
1854 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
ad3217cd 1855 {
8316c618 1856 if (theArgVec[aCompIter][0] == '-')
1857 {
1858 break;
1859 }
1860 }
1861 switch (aNbComps)
1862 {
1863 case 1:
1864 {
1865 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
1866 Standard_CString aName = theArgVec[anArgIter + 1];
1867 if (!Quantity_Color::ColorFromName (aName, aColor))
1868 {
1869 std::cout << "Error: unknown color name '" << aName << "'\n";
1870 return 1;
1871 }
1872 aChangeSet->Color = aColor;
1873 break;
1874 }
1875 case 3:
1876 {
1877 Graphic3d_Vec3d anRgb;
1878 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
1879 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
1880 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
1881 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
1882 || anRgb.y() < 0.0 || anRgb.y() > 1.0
1883 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
1884 {
1885 std::cout << "Error: RGB color values should be within range 0..1!\n";
1886 return 1;
1887 }
1888 aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
1889 break;
1890 }
1891 default:
1892 {
1893 std::cout << "Error: wrong syntax at " << anArg << "\n";
1894 return 1;
1895 }
7fd59977 1896 }
ad3217cd 1897 aChangeSet->ToSetColor = 1;
8316c618 1898 anArgIter += aNbComps;
7fd59977 1899 }
ac116c22 1900 else if (anArg == "-setlinetype")
1901 {
1902 if (++anArgIter >= theArgNb)
1903 {
1904 std::cout << "Error: wrong syntax at " << anArg << "\n";
1905 return 1;
1906 }
1907
1908 TCollection_AsciiString aValue (theArgVec[anArgIter]);
1909 aValue.LowerCase();
1910
1911 if (aValue.IsEqual ("solid"))
1912 {
1913 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
1914 }
1915 else if (aValue.IsEqual ("dot"))
1916 {
1917 aChangeSet->TypeOfLine = Aspect_TOL_DOT;
1918 }
1919 else if (aValue.IsEqual ("dash"))
1920 {
1921 aChangeSet->TypeOfLine = Aspect_TOL_DASH;
1922 }
1923 else if (aValue.IsEqual ("dotdash"))
1924 {
1925 aChangeSet->TypeOfLine = Aspect_TOL_DOTDASH;
1926 }
1927 else
1928 {
1929 std::cout << "Error: wrong syntax at " << anArg << "\n";
1930 return 1;
1931 }
1932
1933 aChangeSet->ToSetTypeOfLine = 1;
1934 }
1935 else if (anArg == "-unsetlinetype")
1936 {
1937 aChangeSet->ToSetTypeOfLine = -1;
1938 }
ad3217cd 1939 else if (anArg == "-unsetcolor")
1940 {
1941 aChangeSet->ToSetColor = -1;
1942 aChangeSet->Color = DEFAULT_COLOR;
1943 }
1944 else if (anArg == "-setmat"
1945 || anArg == "-setmaterial")
1946 {
1947 if (++anArgIter >= theArgNb)
1948 {
1949 std::cout << "Error: wrong syntax at " << anArg << "\n";
1950 return 1;
1951 }
1952 aChangeSet->ToSetMaterial = 1;
1953 aChangeSet->MatName = theArgVec[anArgIter];
1954 aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString());
1955 }
1956 else if (anArg == "-unsetmat"
1957 || anArg == "-unsetmaterial")
1958 {
1959 aChangeSet->ToSetMaterial = -1;
1960 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
1961 }
1962 else if (anArg == "-subshape"
1963 || anArg == "-subshapes")
1964 {
6262338c 1965 if (isDefaults)
1966 {
1967 std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n";
1968 return 1;
1969 }
1970
ad3217cd 1971 if (aNames.IsEmpty())
1972 {
1973 std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n";
1974 return 1;
1975 }
7fd59977 1976
ad3217cd 1977 aChanges.Append (ViewerTest_AspectsChangeSet());
1978 aChangeSet = &aChanges.ChangeLast();
7fd59977 1979
ad3217cd 1980 for (++anArgIter; anArgIter < theArgNb; ++anArgIter)
1981 {
1982 Standard_CString aSubShapeName = theArgVec[anArgIter];
1983 if (*aSubShapeName == '-')
1984 {
1985 --anArgIter;
1986 break;
1987 }
7fd59977 1988
ad3217cd 1989 TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName);
1990 if (aSubShape.IsNull())
1991 {
1992 std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n";
1993 return 1;
1994 }
1995 aChangeSet->SubShapes.Append (aSubShape);
1996 }
7fd59977 1997
ad3217cd 1998 if (aChangeSet->SubShapes.IsEmpty())
1999 {
2000 std::cerr << "Error: empty list is specified after -subshapes!\n";
2001 return 1;
2002 }
2003 }
6262338c 2004 else if (anArg == "-freeboundary"
2005 || anArg == "-fb")
2006 {
2007 if (++anArgIter >= theArgNb)
2008 {
2009 std::cout << "Error: wrong syntax at " << anArg << "\n";
2010 return 1;
2011 }
2012 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2013 aValue.LowerCase();
2014 if (aValue == "on"
2015 || aValue == "1")
2016 {
2017 aChangeSet->ToSetShowFreeBoundary = 1;
2018 }
2019 else if (aValue == "off"
2020 || aValue == "0")
2021 {
2022 aChangeSet->ToSetShowFreeBoundary = -1;
2023 }
2024 else
2025 {
2026 std::cout << "Error: wrong syntax at " << anArg << "\n";
2027 return 1;
2028 }
2029 }
2030 else if (anArg == "-setfreeboundarywidth"
2031 || anArg == "-setfbwidth")
2032 {
2033 if (++anArgIter >= theArgNb)
2034 {
2035 std::cout << "Error: wrong syntax at " << anArg << "\n";
2036 return 1;
2037 }
2038 aChangeSet->ToSetFreeBoundaryWidth = 1;
2039 aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]);
2040 }
2041 else if (anArg == "-unsetfreeboundarywidth"
2042 || anArg == "-unsetfbwidth")
2043 {
2044 aChangeSet->ToSetFreeBoundaryWidth = -1;
2045 aChangeSet->FreeBoundaryWidth = 1.0;
2046 }
2047 else if (anArg == "-setfreeboundarycolor"
2048 || anArg == "-setfbcolor")
2049 {
2050 Standard_Integer aNbComps = 0;
2051 Standard_Integer aCompIter = anArgIter + 1;
2052 for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
2053 {
2054 if (theArgVec[aCompIter][0] == '-')
2055 {
2056 break;
2057 }
2058 }
2059 switch (aNbComps)
2060 {
2061 case 1:
2062 {
2063 Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
2064 Standard_CString aName = theArgVec[anArgIter + 1];
2065 if (!Quantity_Color::ColorFromName (aName, aColor))
2066 {
2067 std::cout << "Error: unknown free boundary color name '" << aName << "'\n";
2068 return 1;
2069 }
2070 aChangeSet->FreeBoundaryColor = aColor;
2071 break;
2072 }
2073 case 3:
2074 {
2075 Graphic3d_Vec3d anRgb;
2076 anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
2077 anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
2078 anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
2079 if (anRgb.x() < 0.0 || anRgb.x() > 1.0
2080 || anRgb.y() < 0.0 || anRgb.y() > 1.0
2081 || anRgb.z() < 0.0 || anRgb.z() > 1.0)
2082 {
2083 std::cout << "Error: free boundary RGB color values should be within range 0..1!\n";
2084 return 1;
2085 }
2086 aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
2087 break;
2088 }
2089 default:
2090 {
2091 std::cout << "Error: wrong syntax at " << anArg << "\n";
2092 return 1;
2093 }
2094 }
2095 aChangeSet->ToSetFreeBoundaryColor = 1;
2096 anArgIter += aNbComps;
2097 }
2098 else if (anArg == "-unsetfreeboundarycolor"
2099 || anArg == "-unsetfbcolor")
2100 {
2101 aChangeSet->ToSetFreeBoundaryColor = -1;
2102 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2103 }
ad3217cd 2104 else if (anArg == "-unset")
2105 {
5bffb882 2106 aChangeSet->ToSetVisibility = 1;
2107 aChangeSet->Visibility = 1;
ad3217cd 2108 aChangeSet->ToSetLineWidth = -1;
2109 aChangeSet->LineWidth = 1.0;
ac116c22 2110 aChangeSet->ToSetTypeOfLine = -1;
2111 aChangeSet->TypeOfLine = Aspect_TOL_SOLID;
ad3217cd 2112 aChangeSet->ToSetTransparency = -1;
2113 aChangeSet->Transparency = 0.0;
2114 aChangeSet->ToSetColor = -1;
2115 aChangeSet->Color = DEFAULT_COLOR;
2116 aChangeSet->ToSetMaterial = -1;
2117 aChangeSet->Material = Graphic3d_NOM_DEFAULT;
6262338c 2118 aChangeSet->ToSetShowFreeBoundary = -1;
2119 aChangeSet->ToSetFreeBoundaryColor = -1;
2120 aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR;
2121 aChangeSet->ToSetFreeBoundaryWidth = -1;
2122 aChangeSet->FreeBoundaryWidth = 1.0;
7fd59977 2123 }
5ad8c033 2124 else if (anArg == "-isoontriangulation"
2125 || anArg == "-isoontriang")
2126 {
2127 if (++anArgIter >= theArgNb)
2128 {
2129 std::cout << "Error: wrong syntax at " << anArg << "\n";
2130 return 1;
2131 }
2132 TCollection_AsciiString aValue (theArgVec[anArgIter]);
2133 aValue.LowerCase();
2134 if (aValue == "on"
2135 || aValue == "1")
2136 {
2137 aChangeSet->ToEnableIsoOnTriangulation = 1;
2138 }
2139 else if (aValue == "off"
2140 || aValue == "0")
2141 {
2142 aChangeSet->ToEnableIsoOnTriangulation = 0;
2143 }
2144 else
2145 {
2146 std::cout << "Error: wrong syntax at " << anArg << "\n";
2147 return 1;
2148 }
2149 }
2150 else if (anArg == "-setmaxparamvalue")
2151 {
2152 if (++anArgIter >= theArgNb)
2153 {
2154 std::cout << "Error: wrong syntax at " << anArg << "\n";
2155 return 1;
2156 }
2157 aChangeSet->ToSetMaxParamValue = 1;
2158 aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]);
2159 }
8a1170ad 2160 else if (anArg == "-setsensitivity")
2161 {
2162 if (isDefaults)
2163 {
2164 std::cout << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!\n";
2165 return 1;
2166 }
2167
2168 if (aNames.IsEmpty())
2169 {
2170 std::cout << "Error: object and selection mode should specified explicitly when -setSensitivity is used!\n";
2171 return 1;
2172 }
2173
2174 if (anArgIter + 2 >= theArgNb)
2175 {
2176 std::cout << "Error: wrong syntax at " << anArg << "\n";
2177 return 1;
2178 }
2179 aChangeSet->ToSetSensitivity = 1;
2180 aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]);
2181 aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]);
2182 }
7fd59977 2183 else
ad3217cd 2184 {
2185 std::cout << "Error: wrong syntax at " << anArg << "\n";
2186 return 1;
2187 }
7fd59977 2188 }
99c56d44 2189
ad3217cd 2190 Standard_Boolean isFirst = Standard_True;
2191 for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2192 aChangesIter.More(); aChangesIter.Next())
2193 {
2194 if (!aChangesIter.Value().Validate (!isFirst))
2195 {
2196 return 1;
2197 }
2198 isFirst = Standard_False;
99c56d44 2199 }
99c56d44 2200
ad3217cd 2201 if (aCtx->HasOpenedContext())
2202 {
2203 aCtx->CloseLocalContext();
99c56d44 2204 }
6262338c 2205
2206 // special case for -defaults parameter.
2207 // all changed values will be set to DefaultDrawer.
2208 if (isDefaults)
2209 {
2210 const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer();
2211
2212 if (aChangeSet->ToSetLineWidth != 0)
2213 {
2214 aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth);
2215 aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth);
2216 aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth);
2217 aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth);
2218 }
2219 if (aChangeSet->ToSetColor != 0)
2220 {
2221 aDrawer->ShadingAspect()->SetColor (aChangeSet->Color);
2222 aDrawer->LineAspect()->SetColor (aChangeSet->Color);
2223 aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color);
2224 aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color);
2225 aDrawer->WireAspect()->SetColor (aChangeSet->Color);
2226 aDrawer->PointAspect()->SetColor (aChangeSet->Color);
2227 }
ac116c22 2228 if (aChangeSet->ToSetTypeOfLine != 0)
2229 {
2230 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2231 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2232 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2233 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2234 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2235 }
6262338c 2236 if (aChangeSet->ToSetTransparency != 0)
2237 {
2238 aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency);
2239 }
2240 if (aChangeSet->ToSetMaterial != 0)
2241 {
2242 aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material);
2243 }
2244 if (aChangeSet->ToSetShowFreeBoundary == 1)
2245 {
2246 aDrawer->SetFreeBoundaryDraw (Standard_True);
2247 }
2248 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2249 {
2250 aDrawer->SetFreeBoundaryDraw (Standard_False);
2251 }
2252 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2253 {
2254 aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth);
2255 }
2256 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2257 {
2258 aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor);
2259 }
5ad8c033 2260 if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2261 {
2262 aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1);
2263 }
2264 if (aChangeSet->ToSetMaxParamValue != 0)
2265 {
2266 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2267 }
6262338c 2268
2269 // redisplay all objects in context
2270 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2271 {
2272 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2273 if (!aPrs.IsNull())
2274 {
2275 aCtx->Redisplay (aPrs, Standard_False);
2276 }
2277 }
2278 return 0;
2279 }
2280
ad3217cd 2281 for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next())
2282 {
6262338c 2283 const TCollection_AsciiString& aName = aPrsIter.CurrentName();
2284 Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current();
2285 Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes();
ad3217cd 2286 Handle(AIS_ColoredShape) aColoredPrs;
2287 Standard_Boolean toDisplay = Standard_False;
6262338c 2288 Standard_Boolean toRedisplay = Standard_False;
5bffb882 2289 if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1)
ad3217cd 2290 {
2291 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs);
2292 if (aShapePrs.IsNull())
2293 {
2294 std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n";
2295 return 1;
2296 }
2297 aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs);
2298 if (aColoredPrs.IsNull())
2299 {
2300 aColoredPrs = new AIS_ColoredShape (aShapePrs);
2301 aCtx->Remove (aShapePrs, Standard_False);
2302 GetMapOfAIS().UnBind2 (aName);
2303 GetMapOfAIS().Bind (aColoredPrs, aName);
2304 toDisplay = Standard_True;
2305 aShapePrs = aColoredPrs;
2306 aPrs = aColoredPrs;
2307 }
2308 }
99c56d44 2309
ad3217cd 2310 if (!aPrs.IsNull())
2311 {
2312 NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges);
2313 aChangeSet = &aChangesIter.ChangeValue();
5bffb882 2314 if (aChangeSet->ToSetVisibility == 1)
2315 {
2316 Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape());
2317 aColDrawer->SetHidden (aChangeSet->Visibility == 0);
2318 }
2319 else if (aChangeSet->ToSetMaterial == 1)
ad3217cd 2320 {
2321 aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False);
2322 }
2323 else if (aChangeSet->ToSetMaterial == -1)
2324 {
2325 aCtx->UnsetMaterial (aPrs, Standard_False);
2326 }
2327 if (aChangeSet->ToSetColor == 1)
2328 {
2329 aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False);
2330 }
2331 else if (aChangeSet->ToSetColor == -1)
2332 {
2333 aCtx->UnsetColor (aPrs, Standard_False);
2334 }
2335 if (aChangeSet->ToSetTransparency == 1)
2336 {
2337 aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False);
2338 }
2339 else if (aChangeSet->ToSetTransparency == -1)
2340 {
2341 aCtx->UnsetTransparency (aPrs, Standard_False);
2342 }
2343 if (aChangeSet->ToSetLineWidth == 1)
2344 {
2345 aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False);
2346 }
2347 else if (aChangeSet->ToSetLineWidth == -1)
2348 {
2349 aCtx->UnsetWidth (aPrs, Standard_False);
2350 }
5ad8c033 2351 else if (aChangeSet->ToEnableIsoOnTriangulation != -1)
2352 {
2353 aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs);
2354 toRedisplay = Standard_True;
2355 }
8a1170ad 2356 else if (aChangeSet->ToSetSensitivity != 0)
2357 {
2358 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2359 }
6262338c 2360 if (!aDrawer.IsNull())
2361 {
2362 if (aChangeSet->ToSetShowFreeBoundary == 1)
2363 {
2364 aDrawer->SetFreeBoundaryDraw (Standard_True);
2365 toRedisplay = Standard_True;
2366 }
2367 else if (aChangeSet->ToSetShowFreeBoundary == -1)
2368 {
2369 aDrawer->SetFreeBoundaryDraw (Standard_False);
2370 toRedisplay = Standard_True;
2371 }
2372 if (aChangeSet->ToSetFreeBoundaryWidth != 0)
2373 {
2374 Handle(Prs3d_LineAspect) aBoundaryAspect =
2375 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2376 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2377 aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth);
2378 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2379 toRedisplay = Standard_True;
2380 }
2381 if (aChangeSet->ToSetFreeBoundaryColor != 0)
2382 {
2383 Handle(Prs3d_LineAspect) aBoundaryAspect =
2384 new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
2385 *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect();
2386 aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor);
2387 aDrawer->SetFreeBoundaryAspect (aBoundaryAspect);
2388 toRedisplay = Standard_True;
2389 }
ac116c22 2390 if (aChangeSet->ToSetTypeOfLine != 0)
2391 {
2392 aDrawer->LineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2393 aDrawer->WireAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2394 aDrawer->FreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2395 aDrawer->UnFreeBoundaryAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2396 aDrawer->SeenLineAspect()->SetTypeOfLine (aChangeSet->TypeOfLine);
2397 toRedisplay = Standard_True;
2398 }
5ad8c033 2399 if (aChangeSet->ToSetMaxParamValue != 0)
2400 {
2401 aDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2402 }
6262338c 2403 }
99c56d44 2404
ad3217cd 2405 for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next())
2406 {
2407 aChangeSet = &aChangesIter.ChangeValue();
2408 for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes);
2409 aSubShapeIter.More(); aSubShapeIter.Next())
2410 {
2411 const TopoDS_Shape& aSubShape = aSubShapeIter.Value();
5bffb882 2412 if (aChangeSet->ToSetVisibility == 1)
2413 {
2414 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2415 aCurColDrawer->SetHidden (aChangeSet->Visibility == 0);
2416 }
ad3217cd 2417 if (aChangeSet->ToSetColor == 1)
2418 {
2419 aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color);
2420 }
2421 if (aChangeSet->ToSetLineWidth == 1)
2422 {
2423 aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth);
2424 }
2425 if (aChangeSet->ToSetColor == -1
2426 || aChangeSet->ToSetLineWidth == -1)
2427 {
2428 aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True);
2429 }
5ad8c033 2430 if (aChangeSet->ToSetMaxParamValue != 0)
2431 {
2432 Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape);
2433 aCurColDrawer->SetMaximalParameterValue (aChangeSet->MaxParamValue);
2434 }
8a1170ad 2435 if (aChangeSet->ToSetSensitivity != 0)
2436 {
2437 aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity);
2438 }
ad3217cd 2439 }
2440 }
2441 if (toDisplay)
2442 {
2443 aCtx->Display (aPrs, Standard_False);
2444 }
6262338c 2445 if (toRedisplay)
2446 {
2447 aCtx->Redisplay (aPrs, Standard_False);
2448 }
ad3217cd 2449 else if (!aColoredPrs.IsNull())
2450 {
36132a2e 2451 aCtx->Redisplay (aColoredPrs, Standard_False);
ad3217cd 2452 }
99c56d44 2453 }
ad3217cd 2454 }
99c56d44 2455 return 0;
2456}
2457
7fd59977 2458//==============================================================================
2459//function : VDonly2
2460//author : ege
2461//purpose : Display only a selected or named object
519d35d8 2462// if there is no selected or named object s, nothing is done
7fd59977 2463//==============================================================================
519d35d8 2464static int VDonly2 (Draw_Interpretor& ,
2465 Standard_Integer theArgNb,
2466 const char** theArgVec)
7fd59977 2467{
519d35d8 2468 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
4e18052b 2469 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
519d35d8 2470 if (aCtx.IsNull())
2471 {
2472 std::cerr << "Error: no active view!\n";
7fd59977 2473 return 1;
519d35d8 2474 }
7fd59977 2475
519d35d8 2476 if (aCtx->HasOpenedContext())
2477 {
2478 aCtx->CloseLocalContext();
2479 }
7fd59977 2480
519d35d8 2481 Standard_Integer anArgIter = 1;
2482 for (; anArgIter < theArgNb; ++anArgIter)
2483 {
4e18052b 2484 if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter]))
519d35d8 2485 {
2486 break;
2487 }
2488 }
7fd59977 2489
519d35d8 2490 NCollection_Map<Handle(Standard_Transient)> aDispSet;
2491 if (anArgIter >= theArgNb)
2492 {
2493 // display only selected objects
c3282ec1 2494 if (aCtx->NbSelected() < 1)
519d35d8 2495 {
2496 return 0;
7fd59977 2497 }
2498
c3282ec1 2499 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
519d35d8 2500 {
c3282ec1 2501 aDispSet.Add (aCtx->SelectedInteractive());
519d35d8 2502 }
2503 }
2504 else
2505 {
2506 // display only specified objects
2507 for (; anArgIter < theArgNb; ++anArgIter)
2508 {
2509 TCollection_AsciiString aName = theArgVec[anArgIter];
2510 if (GetMapOfAIS().IsBound2 (aName))
2511 {
d09dda09 2512 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2513 if (!aShape.IsNull())
519d35d8 2514 {
519d35d8 2515 aCtx->Display (aShape, Standard_False);
d09dda09 2516 aDispSet.Add (aShape);
519d35d8 2517 }
7fd59977 2518 }
2519 }
7fd59977 2520 }
519d35d8 2521
2522 // weed out other objects
2523 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
2524 {
2525 if (aDispSet.Contains (anIter.Key1()))
2526 {
2527 continue;
2528 }
2529
d09dda09 2530 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2531 if (aShape.IsNull())
519d35d8 2532 {
519d35d8 2533 aCtx->Erase (aShape, Standard_False);
2534 }
519d35d8 2535 }
7fd59977 2536 return 0;
2537}
2538
eef7fc64 2539//==============================================================================
2540//function : VRemove
2541//purpose : Removes selected or named objects.
2542// If there is no selected or named objects,
2543// all objects in the viewer can be removed with argument -all.
2544// If -context is in arguments, the object is not deleted from the map of
2545// objects (deleted only from the current context).
2546//==============================================================================
2547int VRemove (Draw_Interpretor& theDI,
519d35d8 2548 Standard_Integer theArgNb,
2549 const char** theArgVec)
eef7fc64 2550{
4e18052b 2551 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2552 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2553 if (aCtx.IsNull())
eef7fc64 2554 {
b6d587e3 2555 std::cerr << "Error: no active view!\n";
eef7fc64 2556 return 1;
2557 }
2558
4e18052b 2559 Standard_Boolean isContextOnly = Standard_False;
2560 Standard_Boolean toRemoveAll = Standard_False;
2561 Standard_Boolean toPrintInfo = Standard_True;
b6d587e3 2562 Standard_Boolean toRemoveLocal = Standard_False;
519d35d8 2563
2564 Standard_Integer anArgIter = 1;
2565 for (; anArgIter < theArgNb; ++anArgIter)
2566 {
2567 TCollection_AsciiString anArg = theArgVec[anArgIter];
2568 anArg.LowerCase();
2569 if (anArg == "-context")
2570 {
2571 isContextOnly = Standard_True;
2572 }
2573 else if (anArg == "-all")
2574 {
2575 toRemoveAll = Standard_True;
2576 }
b7cd4ba7 2577 else if (anArg == "-noinfo")
2578 {
2579 toPrintInfo = Standard_False;
2580 }
b6d587e3 2581 else if (anArg == "-local")
2582 {
2583 toRemoveLocal = Standard_True;
2584 }
2585 else if (anUpdateTool.parseRedrawMode (anArg))
2586 {
2587 continue;
2588 }
2589 else
519d35d8 2590 {
2591 break;
2592 }
2593 }
2594 if (toRemoveAll
2595 && anArgIter < theArgNb)
2596 {
b6d587e3 2597 std::cerr << "Error: wrong syntax!\n";
2598 return 1;
2599 }
2600
2601 if (toRemoveLocal && !aCtx->HasOpenedContext())
2602 {
2603 std::cerr << "Error: local selection context is not open.\n";
519d35d8 2604 return 1;
2605 }
b6d587e3 2606 else if (!toRemoveLocal && aCtx->HasOpenedContext())
2607 {
2608 aCtx->CloseAllContexts (Standard_False);
2609 }
519d35d8 2610
eef7fc64 2611 NCollection_List<TCollection_AsciiString> anIONameList;
519d35d8 2612 if (toRemoveAll)
eef7fc64 2613 {
2614 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2615 anIter.More(); anIter.Next())
2616 {
2617 anIONameList.Append (anIter.Key2());
2618 }
2619 }
519d35d8 2620 else if (anArgIter < theArgNb) // removed objects names are in argument list
eef7fc64 2621 {
519d35d8 2622 for (; anArgIter < theArgNb; ++anArgIter)
eef7fc64 2623 {
519d35d8 2624 TCollection_AsciiString aName = theArgVec[anArgIter];
eef7fc64 2625 if (!GetMapOfAIS().IsBound2 (aName))
2626 {
2627 theDI << aName.ToCString() << " was not bound to some object.\n";
2628 continue;
2629 }
2630
d09dda09 2631 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2632 if (anIO->GetContext() != aCtx)
eef7fc64 2633 {
d09dda09 2634 theDI << aName.ToCString() << " was not displayed in current context.\n";
2635 theDI << "Please activate view with this object displayed and try again.\n";
eef7fc64 2636 continue;
2637 }
2638
d09dda09 2639 anIONameList.Append (aName);
2640 continue;
eef7fc64 2641 }
2642 }
c3282ec1 2643 else if (aCtx->NbSelected() > 0)
eef7fc64 2644 {
2645 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2646 anIter.More(); anIter.Next())
2647 {
2648 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
c3282ec1 2649 if (!aCtx->IsSelected (anIO))
eef7fc64 2650 {
eef7fc64 2651 continue;
2652 }
2653
d09dda09 2654 anIONameList.Append (anIter.Key2());
2655 continue;
eef7fc64 2656 }
2657 }
2658
2659 // Unbind all removed objects from the map of displayed IO.
2660 for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList);
2661 anIter.More(); anIter.Next())
2662 {
519d35d8 2663 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value()));
d09dda09 2664 aCtx->Remove (anIO, Standard_False);
2665 if (toPrintInfo)
519d35d8 2666 {
d09dda09 2667 theDI << anIter.Value().ToCString() << " was removed\n";
519d35d8 2668 }
519d35d8 2669 if (!isContextOnly)
2670 {
2671 GetMapOfAIS().UnBind2 (anIter.Value());
2672 }
2673 }
b6d587e3 2674
2675 // Close local context if it is empty
2676 TColStd_MapOfTransient aLocalIO;
2677 if (aCtx->HasOpenedContext()
2678 && !aCtx->LocalContext()->DisplayedObjects (aLocalIO))
2679 {
2680 aCtx->CloseAllContexts (Standard_False);
2681 }
2682
eef7fc64 2683 return 0;
2684}
2685
7fd59977 2686//==============================================================================
b514beda 2687//function : VErase
2688//purpose : Erase some selected or named objects
7fd59977 2689// if there is no selected or named objects, the whole viewer is erased
7fd59977 2690//==============================================================================
b514beda 2691int VErase (Draw_Interpretor& theDI,
2692 Standard_Integer theArgNb,
2693 const char** theArgVec)
7fd59977 2694{
a1954302 2695 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2696 const Handle(V3d_View)& aView = ViewerTest::CurrentView();
2697 ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
4e18052b 2698 if (aCtx.IsNull())
b514beda 2699 {
b6d587e3 2700 std::cerr << "Error: no active view!\n";
7fd59977 2701 return 1;
b514beda 2702 }
519d35d8 2703
519d35d8 2704 const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall";
2705
2706 Standard_Integer anArgIter = 1;
a272ed94 2707 Standard_Boolean toEraseLocal = Standard_False;
2708 Standard_Boolean toEraseInView = Standard_False;
b6d587e3 2709 TColStd_SequenceOfAsciiString aNamesOfEraseIO;
519d35d8 2710 for (; anArgIter < theArgNb; ++anArgIter)
2711 {
b6d587e3 2712 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2713 anArgCase.LowerCase();
2714 if (anUpdateTool.parseRedrawMode (anArgCase))
519d35d8 2715 {
b6d587e3 2716 continue;
2717 }
2718 else if (anArgCase == "-local")
2719 {
2720 toEraseLocal = Standard_True;
2721 }
a272ed94 2722 else if (anArgCase == "-view"
2723 || anArgCase == "-inview")
2724 {
2725 toEraseInView = Standard_True;
2726 }
b6d587e3 2727 else
2728 {
2729 aNamesOfEraseIO.Append (theArgVec[anArgIter]);
519d35d8 2730 }
2731 }
2732
b6d587e3 2733 if (!aNamesOfEraseIO.IsEmpty() && toEraseAll)
b514beda 2734 {
b6d587e3 2735 std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n";
2736 return 1;
2737 }
7fd59977 2738
b6d587e3 2739 if (toEraseLocal && !aCtx->HasOpenedContext())
2740 {
2741 std::cerr << "Error: local selection context is not open.\n";
2742 return 1;
2743 }
2744 else if (!toEraseLocal && aCtx->HasOpenedContext())
2745 {
2746 aCtx->CloseAllContexts (Standard_False);
2747 }
2748
2749 if (!aNamesOfEraseIO.IsEmpty())
2750 {
2751 // Erase named objects
2752 for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
b514beda 2753 {
b6d587e3 2754 TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
b514beda 2755 if (!GetMapOfAIS().IsBound2 (aName))
2756 {
2757 continue;
2758 }
7fd59977 2759
b514beda 2760 const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName);
2761 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj);
2762 theDI << aName.ToCString() << " ";
2763 if (!anIO.IsNull())
2764 {
a272ed94 2765 if (toEraseInView)
2766 {
2767 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2768 }
2769 else
2770 {
2771 aCtx->Erase (anIO, Standard_False);
2772 }
b514beda 2773 }
7fd59977 2774 }
7fd59977 2775 }
c3282ec1 2776 else if (!toEraseAll && aCtx->NbSelected() > 0)
b514beda 2777 {
b6d587e3 2778 // Erase selected objects
b514beda 2779 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2780 anIter.More(); anIter.Next())
2781 {
2782 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2783 if (!anIO.IsNull()
c3282ec1 2784 && aCtx->IsSelected (anIO))
b514beda 2785 {
2786 theDI << anIter.Key2().ToCString() << " ";
a272ed94 2787 if (toEraseInView)
2788 {
2789 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2790 }
2791 else
2792 {
2793 aCtx->Erase (anIO, Standard_False);
2794 }
7fd59977 2795 }
2796 }
b514beda 2797 }
519d35d8 2798 else
b514beda 2799 {
b6d587e3 2800 // Erase all objects
519d35d8 2801 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2802 anIter.More(); anIter.Next())
b514beda 2803 {
519d35d8 2804 const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2805 if (!anIO.IsNull())
2806 {
a272ed94 2807 if (toEraseInView)
2808 {
2809 aCtx->SetViewAffinity (anIO, aView, Standard_False);
2810 }
2811 else
2812 {
2813 aCtx->Erase (anIO, Standard_False);
2814 }
519d35d8 2815 }
7fd59977 2816 }
7fd59977 2817 }
b6d587e3 2818
7fd59977 2819 return 0;
2820}
2821
7fd59977 2822//==============================================================================
2823//function : VDisplayAll
2824//author : ege
2825//purpose : Display all the objects of the Map
7fd59977 2826//==============================================================================
519d35d8 2827static int VDisplayAll (Draw_Interpretor& ,
2828 Standard_Integer theArgNb,
2829 const char** theArgVec)
7fd59977 2830
2831{
4e18052b 2832 const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
2833 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
2834 if (aCtx.IsNull())
519d35d8 2835 {
b6d587e3 2836 std::cerr << "Error: no active view!\n";
519d35d8 2837 return 1;
2838 }
2839
519d35d8 2840 Standard_Integer anArgIter = 1;
b6d587e3 2841 Standard_Boolean toDisplayLocal = Standard_False;
519d35d8 2842 for (; anArgIter < theArgNb; ++anArgIter)
2843 {
b6d587e3 2844 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
2845 anArgCase.LowerCase();
2846 if (anArgCase == "-local")
2847 {
2848 toDisplayLocal = Standard_True;
2849 }
2850 else if (anUpdateTool.parseRedrawMode (anArgCase))
2851 {
2852 continue;
2853 }
2854 else
519d35d8 2855 {
2856 break;
7fd59977 2857 }
519d35d8 2858 }
2859 if (anArgIter < theArgNb)
2860 {
2861 std::cout << theArgVec[0] << "Error: wrong syntax\n";
2862 return 1;
2863 }
2864
b6d587e3 2865 if (toDisplayLocal && !aCtx->HasOpenedContext())
519d35d8 2866 {
b6d587e3 2867 std::cerr << "Error: local selection context is not open.\n";
2868 return 1;
2869 }
2870 else if (!toDisplayLocal && aCtx->HasOpenedContext())
2871 {
2872 aCtx->CloseLocalContext (Standard_False);
519d35d8 2873 }
2874
2875 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2876 anIter.More(); anIter.Next())
2877 {
d09dda09 2878 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2879 aCtx->Erase (aShape, Standard_False);
519d35d8 2880 }
2881
2882 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
2883 anIter.More(); anIter.Next())
2884 {
d09dda09 2885 const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
2886 aCtx->Display (aShape, Standard_False);
7fd59977 2887 }
2888 return 0;
2889}
2890
c2a388f8 2891//! Auxiliary method to find presentation
2892inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
2893 const Handle(AIS_InteractiveObject)& theIO,
2894 const Standard_Integer theMode)
2895{
2896 if (theIO.IsNull())
2897 {
2898 return Handle(PrsMgr_Presentation)();
2899 }
2900
2901 if (theMode != -1)
2902 {
2903 if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
2904 {
2905 return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
2906 }
2907 }
2908 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
2909 {
2910 return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
2911 }
2912 else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
2913 {
2914 return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
2915 }
2916 return Handle(PrsMgr_Presentation)();
2917}
2918
2919enum ViewerTest_BndAction
2920{
2921 BndAction_Hide,
2922 BndAction_Show,
2923 BndAction_Print
2924};
2925
2926//! Auxiliary method to print bounding box of presentation
2927inline void bndPresentation (Draw_Interpretor& theDI,
2928 const Handle(PrsMgr_Presentation)& thePrs,
2929 const TCollection_AsciiString& theName,
2930 const ViewerTest_BndAction theAction)
2931{
2932 switch (theAction)
2933 {
2934 case BndAction_Hide:
2935 {
2936 thePrs->Presentation()->GraphicUnHighlight();
2937 break;
2938 }
2939 case BndAction_Show:
2940 {
5b111128 2941 Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
a1954302 2942 aPrs->CStructure()->HighlightColor.r = 0.988235f;
2943 aPrs->CStructure()->HighlightColor.g = 0.988235f;
2944 aPrs->CStructure()->HighlightColor.b = 0.988235f;
2945 aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
c2a388f8 2946 break;
2947 }
2948 case BndAction_Print:
2949 {
ed063270 2950 Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
2951 gp_Pnt aMin = aBox.CornerMin();
2952 gp_Pnt aMax = aBox.CornerMax();
c2a388f8 2953 theDI << theName << "\n"
ed063270 2954 << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
2955 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
c2a388f8 2956 break;
2957 }
2958 }
2959}
2960
2961//==============================================================================
2962//function : VBounding
2963//purpose :
2964//==============================================================================
2965int VBounding (Draw_Interpretor& theDI,
2966 Standard_Integer theArgNb,
2967 const char** theArgVec)
2968{
2969 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
4e18052b 2970 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
c2a388f8 2971 if (aCtx.IsNull())
2972 {
2973 std::cout << "Error: no active view!\n";
2974 return 1;
2975 }
2976
4e18052b 2977 ViewerTest_BndAction anAction = BndAction_Show;
2978 Standard_Integer aMode = -1;
c2a388f8 2979
2980 Standard_Integer anArgIter = 1;
2981 for (; anArgIter < theArgNb; ++anArgIter)
2982 {
2983 TCollection_AsciiString anArg (theArgVec[anArgIter]);
2984 anArg.LowerCase();
2985 if (anArg == "-print")
2986 {
2987 anAction = BndAction_Print;
2988 }
2989 else if (anArg == "-show")
2990 {
2991 anAction = BndAction_Show;
2992 }
2993 else if (anArg == "-hide")
2994 {
2995 anAction = BndAction_Hide;
2996 }
2997 else if (anArg == "-mode")
2998 {
2999 if (++anArgIter >= theArgNb)
3000 {
3001 std::cout << "Error: wrong syntax at " << anArg << "\n";
3002 return 1;
3003 }
3004 aMode = Draw::Atoi (theArgVec[anArgIter]);
3005 }
4e18052b 3006 else if (!anUpdateTool.parseRedrawMode (anArg))
c2a388f8 3007 {
3008 break;
3009 }
3010 }
3011
3012 if (anArgIter < theArgNb)
3013 {
3014 // has a list of names
3015 for (; anArgIter < theArgNb; ++anArgIter)
3016 {
3017 TCollection_AsciiString aName = theArgVec[anArgIter];
3018 if (!GetMapOfAIS().IsBound2 (aName))
3019 {
3020 std::cout << "Error: presentation " << aName << " does not exist\n";
3021 return 1;
3022 }
3023
3024 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3025 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3026 if (aPrs.IsNull())
3027 {
3028 std::cout << "Error: presentation " << aName << " does not exist\n";
3029 return 1;
3030 }
3031 bndPresentation (theDI, aPrs, aName, anAction);
3032 }
3033 }
c3282ec1 3034 else if (aCtx->NbSelected() > 0)
c2a388f8 3035 {
3036 // remove all currently selected objects
c3282ec1 3037 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
c2a388f8 3038 {
c3282ec1 3039 Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
c2a388f8 3040 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3041 if (!aPrs.IsNull())
3042 {
3043 bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
3044 }
3045 }
3046 }
3047 else
3048 {
3049 // all objects
3050 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
3051 anIter.More(); anIter.Next())
3052 {
3053 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
3054 Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
3055 if (!aPrs.IsNull())
3056 {
3057 bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
3058 }
3059 }
3060 }
c2a388f8 3061 return 0;
3062}
3063
d399d3c3 3064//==============================================================================
3065//function : VTexture
3066//purpose :
3067//==============================================================================
3068Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv)
7fd59977 3069{
d399d3c3 3070 TCollection_AsciiString aCommandName (theArgv[0]);
7fd59977 3071
900f7229 3072 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs;
d399d3c3 3073 if (aCommandName == "vtexture")
3074 {
3075 if (theArgsNb < 2)
7fd59977 3076 {
d399d3c3 3077 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
3078 std::cout << "Type help for more information.\n";
31160f80 3079 return 1;
7fd59977 3080 }
3081
d399d3c3 3082 // look for options of vtexture command
3083 TCollection_AsciiString aParseKey;
3084 for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt)
3085 {
3086 TCollection_AsciiString anArg (theArgv [anArgIt]);
7fd59977 3087
d399d3c3 3088 anArg.UpperCase();
3089 if (anArg.Value (1) == '-' && !anArg.IsRealValue())
3090 {
3091 aParseKey = anArg;
3092 aParseKey.Remove (1);
3093 aParseKey.UpperCase();
900f7229 3094 aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString);
d399d3c3 3095 continue;
3096 }
3097
3098 if (aParseKey.IsEmpty())
3099 {
3100 continue;
3101 }
3102
900f7229 3103 aMapOfArgs(aParseKey)->Append (anArg);
d399d3c3 3104 }
3105 }
3106 else if (aCommandName == "vtexscale"
3107 || aCommandName == "vtexorigin"
3108 || aCommandName == "vtexrepeat")
3109 {
3110 // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands
3111 // equal to -scale, -origin, -repeat options of vtexture command
3112 if (theArgsNb < 2 || theArgsNb > 4)
7fd59977 3113 {
d399d3c3 3114 std::cout << theArgv[0] << ": " << " invalid arguments.\n";
3115 std::cout << "Type help for more information.\n";
31160f80 3116 return 1;
7fd59977 3117 }
3118
900f7229 3119 Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString;
d399d3c3 3120 if (theArgsNb == 2)
3121 {
900f7229 3122 anArgs->Append ("OFF");
d399d3c3 3123 }
3124 else if (theArgsNb == 4)
3125 {
900f7229 3126 anArgs->Append (TCollection_AsciiString (theArgv[2]));
3127 anArgs->Append (TCollection_AsciiString (theArgv[3]));
d399d3c3 3128 }
7fd59977 3129
d399d3c3 3130 TCollection_AsciiString anArgKey;
3131 if (aCommandName == "vtexscale")
3132 {
3133 anArgKey = "SCALE";
3134 }
3135 else if (aCommandName == "vtexorigin")
3136 {
3137 anArgKey = "ORIGIN";
3138 }
3139 else
3140 {
3141 anArgKey = "REPEAT";
3142 }
3143
3144 aMapOfArgs.Bind (anArgKey, anArgs);
3145 }
3146 else if (aCommandName == "vtexdefault")
7fd59977 3147 {
d399d3c3 3148 // scan for parameters of vtexdefault command
3149 // equal to -default option of vtexture command
900f7229 3150 aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString);
7fd59977 3151 }
3152
d399d3c3 3153 // Check arguments for validity
900f7229 3154 NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs);
d399d3c3 3155 for (; aMapIt.More(); aMapIt.Next())
3156 {
3157 const TCollection_AsciiString& aKey = aMapIt.Key();
900f7229 3158 const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value();
d399d3c3 3159
3160 // -scale, -origin, -repeat: one argument "off", or two real values
3161 if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT"))
900f7229 3162 && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF")
3163 || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue())))
7fd59977 3164 {
d399d3c3 3165 continue;
7fd59977 3166 }
d399d3c3 3167
3168 // -modulate: single argument "on" / "off"
900f7229 3169 if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON"))
d399d3c3 3170 {
3171 continue;
3172 }
3173
3174 // -default: no arguments
900f7229 3175 if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty())
d399d3c3 3176 {
3177 continue;
3178 }
3179
3180 TCollection_AsciiString aLowerKey;
3181 aLowerKey = "-";
3182 aLowerKey += aKey;
3183 aLowerKey.LowerCase();
3184 std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n";
3185 std::cout << "Type help for more information.\n";
3186 return 1;
3187 }
3188
3189 Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
3190 if (anAISContext.IsNull())
3191 {
3192 std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n";
3193 return 1;
3194 }
3195
3196 Standard_Integer aPreviousMode = 0;
3197
3198 ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL);
3199
3200 TCollection_AsciiString aShapeName (theArgv[1]);
3201 Handle(AIS_InteractiveObject) anIO;
3202
3203 const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS();
3204 if (aMapOfIO.IsBound2 (aShapeName))
3205 {
3206 anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName));
3207 }
3208
3209 if (anIO.IsNull())
3210 {
3211 std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n";
3212 return 1;
3213 }
3214
3215 Handle(AIS_TexturedShape) aTexturedIO;
3216 if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape)))
3217 {
3218 aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO);
3219 aPreviousMode = aTexturedIO->DisplayMode();
3220 }
7fd59977 3221 else
d399d3c3 3222 {
2195ab96 3223 anAISContext->Remove (anIO, Standard_False);
d399d3c3 3224 aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1]));
3225 GetMapOfAIS().UnBind1 (anIO);
3226 GetMapOfAIS().UnBind2 (aShapeName);
3227 GetMapOfAIS().Bind (aTexturedIO, aShapeName);
3228 }
3229
3230 // -------------------------------------------
3231 // Turn texturing on/off - only for vtexture
3232 // -------------------------------------------
3233
3234 if (aCommandName == "vtexture")
3235 {
3236 TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : "");
3237
3238 if (aTextureArg.IsEmpty())
7fd59977 3239 {
d399d3c3 3240 std::cout << aCommandName << ": " << " Texture mapping disabled.\n";
3241 std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n";
3242
3243 anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False);
3244 if (aPreviousMode == 3)
3245 {
3246 anAISContext->RecomputePrsOnly (aTexturedIO);
3247 }
3248
3249 anAISContext->Display (aTexturedIO, Standard_True);
3250 return 0;
7fd59977 3251 }
d399d3c3 3252 else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument
7fd59977 3253 {
d399d3c3 3254 if (aTextureArg == "?")
3255 {
3256 TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder();
7fd59977 3257
d399d3c3 3258 theDi << "\n Files in current directory : \n" << "\n";
3259 theDi.Eval ("glob -nocomplain *");
7fd59977 3260
d399d3c3 3261 TCollection_AsciiString aCmnd ("glob -nocomplain ");
3262 aCmnd += aTextureFolder;
3263 aCmnd += "/* ";
7fd59977 3264
d399d3c3 3265 theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n";
3266 theDi.Eval (aCmnd.ToCString());
3267 return 0;
3268 }
3269 else
3270 {
3271 aTexturedIO->SetTextureFileName (aTextureArg);
3272 }
3273 }
3274 }
7fd59977 3275
d399d3c3 3276 // ------------------------------------
3277 // Process other options and commands
3278 // ------------------------------------
7fd59977 3279
900f7229 3280 Handle(TColStd_HSequenceOfAsciiString) aValues;
d399d3c3 3281 if (aMapOfArgs.Find ("DEFAULT", aValues))
3282 {
3283 aTexturedIO->SetTextureRepeat (Standard_False);
3284 aTexturedIO->SetTextureOrigin (Standard_False);
3285 aTexturedIO->SetTextureScale (Standard_False);
3286 aTexturedIO->EnableTextureModulate();
3287 }
3288 else
3289 {
3290 if (aMapOfArgs.Find ("SCALE", aValues))
3291 {
900f7229 3292 if (aValues->Value(1) != "OFF")
d399d3c3 3293 {
900f7229 3294 aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3295 }
7fd59977 3296 else
d399d3c3 3297 {
3298 aTexturedIO->SetTextureScale (Standard_False);
3299 }
3300 }
7fd59977 3301
d399d3c3 3302 if (aMapOfArgs.Find ("ORIGIN", aValues))
3303 {
900f7229 3304 if (aValues->Value(1) != "OFF")
d399d3c3 3305 {
900f7229 3306 aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3307 }
3308 else
3309 {
3310 aTexturedIO->SetTextureOrigin (Standard_False);
3311 }
3312 }
7fd59977 3313
d399d3c3 3314 if (aMapOfArgs.Find ("REPEAT", aValues))
3315 {
900f7229 3316 if (aValues->Value(1) != "OFF")
d399d3c3 3317 {
900f7229 3318 aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue());
d399d3c3 3319 }
3320 else
3321 {
3322 aTexturedIO->SetTextureRepeat (Standard_False);
3323 }
7fd59977 3324 }
3325
d399d3c3 3326 if (aMapOfArgs.Find ("MODULATE", aValues))
7fd59977 3327 {
900f7229 3328 if (aValues->Value(1) == "ON")
d399d3c3 3329 {
3330 aTexturedIO->EnableTextureModulate();
3331 }
3332 else
3333 {
3334 aTexturedIO->DisableTextureModulate();
3335 }
7fd59977 3336 }
d399d3c3 3337 }
3338
3339 if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3)
3340 {
3341 anAISContext->RecomputePrsOnly (aTexturedIO);
3342 }
3343 else
3344 {
3345 anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False);
3346 anAISContext->Display (aTexturedIO, Standard_True);
3347 anAISContext->Update (aTexturedIO,Standard_True);
3348 }
3349
31160f80 3350 return 0;
7fd59977 3351}
3352
af65fb19 3353//! Auxiliary method to parse transformation persistence flags
3354inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString,
3355 Standard_Integer& theFlags)
3356{
3357 if (theFlagString == "pan")
3358 {
3359 theFlags |= Graphic3d_TMF_PanPers;
3360 }
3361 else if (theFlagString == "zoom")
3362 {
3363 theFlags |= Graphic3d_TMF_ZoomPers;
3364 }
3365 else if (theFlagString == "rotate")
3366 {
3367 theFlags |= Graphic3d_TMF_RotatePers;
3368 }
3369 else if (theFlagString == "trihedron")
3370 {
3371 theFlags = Graphic3d_TMF_TriedronPers;
3372 }
3373 else if (theFlagString == "full")
3374 {
3375 theFlags = Graphic3d_TMF_FullPers;
3376 }
3377 else if (theFlagString == "none")
3378 {
3379 theFlags = Graphic3d_TMF_None;
3380 }
3381 else
3382 {
3383 return Standard_False;
3384 }
3385
3386 return Standard_True;
3387}
3388
7fd59977 3389//==============================================================================
3390//function : VDisplay2
3391//author : ege
3392//purpose : Display an object from its name
7fd59977 3393//==============================================================================
519d35d8 3394static int VDisplay2 (Draw_Interpretor& theDI,
3395 Standard_Integer theArgNb,
3396 const char** theArgVec)
7fd59977 3397{
519d35d8 3398 if (theArgNb < 2)
3399 {
b6d587e3 3400 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
519d35d8 3401 return 1;
3402 }
b6d587e3 3403
3404 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
3405 if (aCtx.IsNull())
519d35d8 3406 {
7fd59977 3407 ViewerTest::ViewerInit();
4e18052b 3408 aCtx = ViewerTest::GetAISContext();
7fd59977 3409 }
3410
b6d587e3 3411 // Parse input arguments
4e18052b 3412 ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView());
a1954302 3413 Standard_Integer isMutable = -1;
3414 Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN;
3415 Standard_Boolean toDisplayLocal = Standard_False;
3416 Standard_Boolean toReDisplay = Standard_False;
af65fb19 3417 Standard_Integer isSelectable = -1;
3418 Standard_Integer anObjDispMode = -2;
3419 Standard_Integer anObjHighMode = -2;
3420 Standard_Boolean toSetTrsfPers = Standard_False;
3421 Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None;
3422 gp_Pnt aTPPosition;
b6d587e3 3423 TColStd_SequenceOfAsciiString aNamesOfDisplayIO;
a1954302 3424 AIS_DisplayStatus aDispStatus = AIS_DS_None;
a272ed94 3425 Standard_Integer toDisplayInView = Standard_False;
519d35d8 3426 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
3427 {
b7cd4ba7 3428 const TCollection_AsciiString aName = theArgVec[anArgIter];
3429 TCollection_AsciiString aNameCase = aName;
3430 aNameCase.LowerCase();
4e18052b 3431 if (anUpdateTool.parseRedrawMode (aName))
519d35d8 3432 {
3433 continue;
3434 }
b7cd4ba7 3435 else if (aNameCase == "-mutable")
3436 {
3437 isMutable = 1;
b7cd4ba7 3438 }
a1954302 3439 else if (aNameCase == "-neutral")
3440 {
3441 aDispStatus = AIS_DS_Displayed;
3442 }
3443 else if (aNameCase == "-immediate"
3444 || aNameCase == "-top")
3445 {
3446 aZLayer = Graphic3d_ZLayerId_Top;
3447 }
3448 else if (aNameCase == "-topmost")
3449 {
3450 aZLayer = Graphic3d_ZLayerId_Topmost;
3451 }
3452 else if (aNameCase == "-osd"
af65fb19 3453 || aNameCase == "-toposd"
3454 || aNameCase == "-overlay")
a1954302 3455 {
3456 aZLayer = Graphic3d_ZLayerId_TopOSD;
3457 }
af65fb19 3458 else if (aNameCase == "-botosd"
3459 || aNameCase == "-underlay")
3460 {
3461 aZLayer = Graphic3d_ZLayerId_BotOSD;
3462 }
3463 else if (aNameCase == "-select"
3464 || aNameCase == "-selectable")
3465 {
3466 isSelectable = 1;
3467 }
3468 else if (aNameCase == "-noselect"
3469 || aNameCase == "-noselection")
3470 {
3471 isSelectable = 0;
3472 }
3473 else if (aNameCase == "-dispmode"
3474 || aNameCase == "-displaymode")
3475 {
3476 if (++anArgIter >= theArgNb)
3477 {
3478 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3479 return 1;
3480 }
3481
3482 anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
3483 }
3484 else if (aNameCase == "-highmode"
3485 || aNameCase == "-highlightmode")
3486 {
3487 if (++anArgIter >= theArgNb)
3488 {
3489 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3490 return 1;
3491 }
3492
3493 anObjHighMode = Draw::Atoi (theArgVec [anArgIter]);
3494 }
3495 else if (aNameCase == "-3d")
3496 {
3497 toSetTrsfPers = Standard_True;
3498 aTrsfPersFlags = Graphic3d_TMF_None;
3499 }
3500 else if (aNameCase == "-2d")
3501 {
3502 toSetTrsfPers = Standard_True;
3503 aTrsfPersFlags = Graphic3d_TMF_2d;
3504 }
3505 else if (aNameCase == "-2dtopdown")
3506 {
3507 toSetTrsfPers = Standard_True;
3508 aTrsfPersFlags = Graphic3d_TMF_2d | Graphic3d_TMF_2d_IsTopDown;
3509 }
3510 else if (aNameCase == "-trsfpers"
3511 || aNameCase == "-pers")
3512 {
3513 if (++anArgIter >= theArgNb)
3514 {
3515 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3516 return 1;
3517 }
3518
3519 toSetTrsfPers = Standard_True;
3520 aTrsfPersFlags = Graphic3d_TMF_None;
3521 TCollection_AsciiString aPersFlags (theArgVec [anArgIter]);
3522 aPersFlags.LowerCase();
3523 for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|"))
3524 {
3525 if (aParserPos == -1)
3526 {
3527 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3528 {
3529 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3530 return 1;
3531 }
3532 break;
3533 }
3534
3535 TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1);
3536 if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags))
3537 {
3538 std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n";
3539 return 1;
3540 }
3541 aPersFlags = anOtherFlags;
3542 }
3543 }
3544 else if (aNameCase == "-trsfperspos"
3545 || aNameCase == "-perspos")
3546 {
3547 if (anArgIter + 2 >= theArgNb)
3548 {
3549 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3550 return 1;
3551 }
3552
3553 TCollection_AsciiString aX (theArgVec[++anArgIter]);
3554 TCollection_AsciiString aY (theArgVec[++anArgIter]);
3555 TCollection_AsciiString aZ = "0";
3556 if (!aX.IsIntegerValue()
3557 || !aY.IsIntegerValue())
3558 {
3559 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3560 return 1;
3561 }
3562 if (anArgIter + 1 < theArgNb)
3563 {
3564 TCollection_AsciiString aTemp = theArgVec[anArgIter + 1];
3565 if (aTemp.IsIntegerValue())
3566 {
3567 aZ = aTemp;
3568 ++anArgIter;
3569 }
3570 }
3571 aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue());
3572 }
a1954302 3573 else if (aNameCase == "-layer")
3574 {
3575 if (++anArgIter >= theArgNb)
3576 {
3577 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3578 return 1;
3579 }
3580
3581 TCollection_AsciiString aValue (theArgVec[anArgIter]);
3582 if (!aValue.IsIntegerValue())
3583 {
3584 std::cerr << "Error: wrong syntax at " << aName << ".\n";
3585 return 1;
3586 }
3587
3588 aZLayer = aValue.IntegerValue();
3589 }
a272ed94 3590 else if (aNameCase == "-view"
3591 || aNameCase == "-inview")
3592 {
3593 toDisplayInView = Standard_True;
3594 }
b6d587e3 3595 else if (aNameCase == "-local")
3596 {
a1954302 3597 aDispStatus = AIS_DS_Temporary;
b6d587e3 3598 toDisplayLocal = Standard_True;
3599 }
a1954302 3600 else if (aNameCase == "-redisplay")
3601 {
3602 toReDisplay = Standard_True;
3603 }
b6d587e3 3604 else
3605 {
3606 aNamesOfDisplayIO.Append (aName);
3607 }
3608 }
3609
3610 if (aNamesOfDisplayIO.IsEmpty())
3611 {
3612 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
3613 return 1;
3614 }
3615
3616 // Prepare context for display
3617 if (toDisplayLocal && !aCtx->HasOpenedContext())
3618 {
3619 aCtx->OpenLocalContext (Standard_False);
3620 }
3621 else if (!toDisplayLocal && aCtx->HasOpenedContext())
3622 {
3623 aCtx->CloseAllContexts (Standard_False);
3624 }
3625
3626 // Display interactive objects
3627 for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter)
3628 {
3629 const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter);
3630
3631 if (!GetMapOfAIS().IsBound2 (aName))
519d35d8 3632 {
3633 // create the AIS_Shape from a name
3634 const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString());
3635 if (!aShape.IsNull())
3636 {
b7cd4ba7 3637 if (isMutable != -1)
3638 {
3639 aShape->SetMutable (isMutable == 1);
3640 }
a1954302 3641 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3642 {
3643 aShape->SetZLayer (aZLayer);
3644 }
af65fb19 3645 if (toSetTrsfPers)
3646 {
3647 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3648 }
3649 if (anObjDispMode != -2)
3650 {
3651 aShape->SetDisplayMode (anObjDispMode);
3652 }
3653 if (anObjHighMode != -2)
3654 {
3655 aShape->SetHilightMode (anObjHighMode);
3656 }
b3c433fe 3657 if (!toDisplayLocal)
3658 GetMapOfAIS().Bind (aShape, aName);
a1954302 3659
3660 Standard_Integer aDispMode = aShape->HasDisplayMode()
3661 ? aShape->DisplayMode()
3662 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3663 ? aCtx->DisplayMode()
3664 : 0);
af65fb19 3665 Standard_Integer aSelMode = -1;
825aa485 3666 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
af65fb19 3667 {
c3282ec1 3668 aSelMode = aShape->GlobalSelectionMode();
af65fb19 3669 }
a1954302 3670
3671 aCtx->Display (aShape, aDispMode, aSelMode,
3672 Standard_False, aShape->AcceptShapeDecomposition(),
3673 aDispStatus);
a272ed94 3674 if (toDisplayInView)
3675 {
3676 for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews())
3677 {
3678 aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False);
3679 }
3680 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
3681 }
519d35d8 3682 }
af65fb19 3683 else
3684 {
3685 std::cerr << "Error: object with name '" << aName << "' does not exist!\n";
3686 }
519d35d8 3687 continue;
3688 }
7fd59977 3689
d09dda09 3690 Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
3691 if (isMutable != -1)
519d35d8 3692 {
d09dda09 3693 aShape->SetMutable (isMutable == 1);
3694 }
3695 if (aZLayer != Graphic3d_ZLayerId_UNKNOWN)
3696 {
3697 aShape->SetZLayer (aZLayer);
3698 }
3699 if (toSetTrsfPers)
3700 {
3701 aShape->SetTransformPersistence (aTrsfPersFlags, aTPPosition);
3702 }
3703 if (anObjDispMode != -2)
3704 {
3705 aShape->SetDisplayMode (anObjDispMode);
3706 }
3707 if (anObjHighMode != -2)
3708 {
3709 aShape->SetHilightMode (anObjHighMode);
3710 }
3711 Standard_Integer aDispMode = aShape->HasDisplayMode()
3712 ? aShape->DisplayMode()
3713 : (aShape->AcceptDisplayMode (aCtx->DisplayMode())
3714 ? aCtx->DisplayMode()
3715 : 0);
3716 Standard_Integer aSelMode = -1;
825aa485 3717 if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection()))
d09dda09 3718 {
c3282ec1 3719 aSelMode = aShape->GlobalSelectionMode();
d09dda09 3720 }
3721
3722 if (aShape->Type() == AIS_KOI_Datum)
3723 {
3724 aCtx->Display (aShape, Standard_False);
3725 }
3726 else
3727 {
3728 theDI << "Display " << aName.ToCString() << "\n";
3729
3730 // update the Shape in the AIS_Shape
3731 TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString());
3732 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape);
3733 if (!aShapePrs.IsNull())
af65fb19 3734 {
d09dda09 3735 if (!aShapePrs->Shape().IsEqual (aNewShape))
3736 {
3737 toReDisplay = Standard_True;
3738 }
3739 aShapePrs->Set (aNewShape);
af65fb19 3740 }
d09dda09 3741 if (toReDisplay)
af65fb19 3742 {
d09dda09 3743 aCtx->Redisplay (aShape, Standard_False);
af65fb19 3744 }
b7cd4ba7 3745
d09dda09 3746 if (aSelMode == -1)
519d35d8 3747 {
d09dda09 3748 aCtx->Erase (aShape);
519d35d8 3749 }
d09dda09 3750 aCtx->Display (aShape, aDispMode, aSelMode,
3751 Standard_False, aShape->AcceptShapeDecomposition(),
3752 aDispStatus);
3753 if (toDisplayInView)
519d35d8 3754 {
d09dda09 3755 aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True);
7fd59977 3756 }
3757 }
7fd59977 3758 }
b6d587e3 3759
7fd59977 3760 return 0;
3761}
3762
f3889691 3763//===============================================================================================
3764//function : VUpdate
3765//purpose :
3766//===============================================================================================
3767static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec)
3768{
3769 Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext();
3770 if (aContextAIS.IsNull())
3771 {
3772 std::cout << theArgVec[0] << "AIS context is not available.\n";
3773 return 1;
3774 }
3775
3776 if (theArgsNb < 2)
3777 {
3778 std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n";
3779 return 1;
3780 }
3781
3782 const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS();
3783
3784 AIS_ListOfInteractive aListOfIO;
3785
3786 for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
3787 {
3788 TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]);
3789
3790 Handle(AIS_InteractiveObject) anAISObj;
3791 if (anAISMap.IsBound2 (aName))
3792 {
3793 anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName));
3794 }
3795
3796 if (anAISObj.IsNull())
3797 {
3798 std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n";
3799 return 1;
3800 }
3801
3802 aListOfIO.Append (anAISObj);
3803 }
3804
3805 AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO);
3806 for (; anIOIt.More(); anIOIt.Next())
3807 {
3808 aContextAIS->Update (anIOIt.Value(), Standard_False);
3809 }
3810
3811 aContextAIS->UpdateCurrentViewer();
3812
3813 return 0;
3814}
3815
7fd59977 3816//==============================================================================
3817//function : VPerf
3818//purpose : Test the annimation of an object along a
3819// predifined trajectory
3820//Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)
3821//==============================================================================
3822
3823static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) {
3824
3825 OSD_Timer myTimer;
3826 if (TheAISContext()->HasOpenedContext())
3827 TheAISContext()->CloseLocalContext();
3828
c6541a0c 3829 Standard_Real Step=4*M_PI/180;
7fd59977 3830 Standard_Real Angle=0;
3831
3832 Handle(AIS_InteractiveObject) aIO;
3833 if (GetMapOfAIS().IsBound2(argv[1]))
3834 aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
3835 if (aIO.IsNull())
3836 return 1;
3837
3838 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO);
3839
3840 myTimer.Start();
3841
91322f44 3842 if (Draw::Atoi(argv[3])==1 ) {
7fd59977 3843 di<<" Primitives sensibles OFF"<<"\n";
3844 TheAISContext()->Deactivate(aIO);
3845 }
3846 else {
3847 di<<" Primitives sensibles ON"<<"\n";
3848 }
3849 // Movement par transformation
91322f44 3850 if(Draw::Atoi(argv[2]) ==1) {
7fd59977 3851 di<<" Calcul par Transformation"<<"\n";
c6541a0c 3852 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 3853
3854 Angle=Step*myAngle;
3855 gp_Trsf myTransfo;
3856 myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle );
3857 TheAISContext()->SetLocation(aShape,myTransfo);
3858 TheAISContext() ->UpdateCurrentViewer();
3859
3860 }
3861 }
3862 else {
3863 di<<" Calcul par Locations"<<"\n";
3864 gp_Trsf myAngleTrsf;
3865 myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step );
3866 TopLoc_Location myDeltaAngle (myAngleTrsf);
3867 TopLoc_Location myTrueLoc;
3868
c6541a0c 3869 for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) {
7fd59977 3870
3871 Angle=Step*myAngle;
3872 myTrueLoc=myTrueLoc*myDeltaAngle;
3873 TheAISContext()->SetLocation(aShape,myTrueLoc );
3874 TheAISContext() ->UpdateCurrentViewer();
3875 }
3876 }
91322f44 3877 if (Draw::Atoi(argv[3])==1 ){
7fd59977 3878 // On reactive la selection des primitives sensibles
3879 TheAISContext()->Activate(aIO,0);
3880 }
3881 a3DView() -> Redraw();
3882 myTimer.Stop();
3883 di<<" Temps ecoule "<<"\n";
3884 myTimer.Show();
3885 return 0;
3886}
3887
3888
3889//==================================================================================
3890// Function : VAnimation
3891//==================================================================================
3892static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) {
31160f80 3893 if (argc != 5) {
7fd59977 3894 di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n";
3895 return 1;
3896 }
3897
3898 Standard_Real thread = 4;
3899 Standard_Real angleA=0;
3900 Standard_Real angleB;
3901 Standard_Real X;
3902 gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1));
3903
3904 BRep_Builder B;
3905 TopoDS_Shape CrankArm;
3906 TopoDS_Shape CylinderHead;
3907 TopoDS_Shape Propeller;
3908 TopoDS_Shape EngineBlock;
3909
3910 //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B);
3911 //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B);
3912 //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B);
3913 //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B);
3914 BRepTools::Read(CrankArm,argv[1],B);
3915 BRepTools::Read(CylinderHead,argv[2],B);
3916 BRepTools::Read(Propeller,argv[3],B);
3917 BRepTools::Read(EngineBlock,argv[4],B);
3918
3919 if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";}
3920
3921
3922 OSD_Timer myTimer;
3923 myTimer.Start();
3924
3925 Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead);
3926 Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock);
3927 Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm);
3928 Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller);
3929
3930 GetMapOfAIS().Bind(myAisCylinderHead,"a");
3931 GetMapOfAIS().Bind(myAisEngineBlock,"b");
3932 GetMapOfAIS().Bind(myAisCrankArm,"c");
3933 GetMapOfAIS().Bind(myAisPropeller,"d");
3934
b7cd4ba7 3935 myAisCylinderHead->SetMutable (Standard_True);
3936 myAisEngineBlock ->SetMutable (Standard_True);
3937 myAisCrankArm ->SetMutable (Standard_True);
3938 myAisPropeller ->SetMutable (Standard_True);
7fd59977 3939
b7cd4ba7 3940 TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED);
3941 TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED);
3942 TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN);
3943
3944 TheAISContext()->Display (myAisCylinderHead, Standard_False);
3945 TheAISContext()->Display (myAisEngineBlock, Standard_False);
3946 TheAISContext()->Display (myAisCrankArm, Standard_False);
3947 TheAISContext()->Display (myAisPropeller, Standard_False);
7fd59977 3948
3949 TheAISContext()->Deactivate(myAisCylinderHead);
3950 TheAISContext()->Deactivate(myAisEngineBlock );
3951 TheAISContext()->Deactivate(myAisCrankArm );
3952 TheAISContext()->Deactivate(myAisPropeller );
3953
3954 // Boucle de mouvement
c6541a0c 3955 for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) {
7fd59977 3956
c6541a0c 3957 angleA = thread*myAngle*M_PI/180;
7fd59977 3958 X = Sin(angleA)*3/8;
3959 angleB = atan(X / Sqrt(-X * X + 1));
3960 Standard_Real decal(25*0.6);
3961
3962
3963 //Build a transformation on the display
3964 gp_Trsf aPropellerTrsf;
3965 aPropellerTrsf.SetRotation(Ax1,angleA);
3966 TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf);
3967
3968 gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)),-3*decal*Sin(angleA),0),gp_Vec(0,0,1),gp_Vec(1,0,0));
3969 gp_Trsf aCrankArmTrsf;
3970 aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB));
3971 TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf);
3972
3973 TheAISContext()->UpdateCurrentViewer();
3974 }
3975
0717ddc1 3976 TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() );
3977 TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() );
7fd59977 3978
0717ddc1 3979 myAisCrankArm ->ResetTransformation();
3980 myAisPropeller->ResetTransformation();
7fd59977 3981
3982 myAisCrankArm -> Set(myNewCrankArm );
3983 myAisPropeller -> Set(myNewPropeller);
3984
3985 TheAISContext()->Activate(myAisCylinderHead,0);
3986 TheAISContext()->Activate(myAisEngineBlock,0 );
3987 TheAISContext()->Activate(myAisCrankArm ,0 );
3988 TheAISContext()->Activate(myAisPropeller ,0 );
3989
3990 myTimer.Stop();
3991 myTimer.Show();
3992 myTimer.Start();
3993
3994 TheAISContext()->Redisplay(myAisCrankArm ,Standard_False);
3995 TheAISContext()->Redisplay(myAisPropeller,Standard_False);
3996
3997 TheAISContext()->UpdateCurrentViewer();
3998 a3DView()->Redraw();
3999
4000 myTimer.Stop();
4001 myTimer.Show();
4002
4003 return 0;
4004
4005}
4006
4007//==============================================================================
4008//function : VShading
4009//purpose : Sharpen or roughten the quality of the shading
4010//Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg
4011//==============================================================================
5cbef0fe
S
4012static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv)
4013{
7fd59977 4014 Standard_Real myDevCoef;
4015 Handle(AIS_InteractiveObject) TheAisIO;
4016
4017 // Verifications
5cbef0fe
S
4018 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0);
4019
7fd59977 4020 if (TheAISContext()->HasOpenedContext())
4021 TheAISContext()->CloseLocalContext();
4022
4023 if (argc < 3) {
4024 myDevCoef = 0.0008;
4025 } else {
91322f44 4026 myDevCoef =Draw::Atof(argv[2]);
7fd59977 4027 }
4028
7fd59977 4029 TCollection_AsciiString name=argv[1];
4030 if (GetMapOfAIS().IsBound2(name ))
5cbef0fe 4031 TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name));
7fd59977 4032 if (TheAisIO.IsNull())
4033 TheAisIO=GetAISShapeFromName((const char *)name.ToCString());
4034
5cbef0fe 4035 if (HaveToSet)
7fd59977 4036 TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True);
5cbef0fe 4037 else
7fd59977 4038 TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True);
4039
7fd59977 4040 TheAISContext()->Redisplay(TheAisIO);
4041 return 0;
4042}
4043//==============================================================================
4044//function : HaveMode
4045//use : VActivatedModes
4046//==============================================================================
4047#include <TColStd_ListIteratorOfListOfInteger.hxx>
4048
4049Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode )
4050{
4051 TColStd_ListOfInteger List;
4052 TheAISContext()->ActivatedModes (TheAisIO,List);
4053 TColStd_ListIteratorOfListOfInteger it;
4054 Standard_Boolean Found=Standard_False;
4055 for (it.Initialize(List); it.More()&&!Found; it.Next() ){
4056 if (it.Value()==mode ) Found=Standard_True;
4057 }
4058 return Found;
4059}
4060
4061
4062
4063//==============================================================================
4064//function : VActivatedMode
4065//author : ege
4066//purpose : permet d'attribuer a chacune des shapes un mode d'activation
4067// (edges,vertex...)qui lui est propre et le mode de selection standard.
4068// La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer)
4069// Dans le cas ou on veut psser la shape en argument, la fonction n'autorise
4070// qu'un nom et qu'un mode.
4071//Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7)
4072//==============================================================================
4073#include <AIS_ListIteratorOfListOfInteractive.hxx>
4074
4075static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4076
4077{
7fd59977 4078 Standard_Boolean ThereIsName = Standard_False ;
4079
4080 if(!a3DView().IsNull()){
4081
5cbef0fe 4082 const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0);
7fd59977 4083 // verification des arguments
4084 if (HaveToSet) {
4085 if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;}
5cbef0fe 4086 ThereIsName = (argc == 3);
7fd59977 4087 }
4088 else {
4089 // vunsetam
4090 if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;}
4091 else {
5cbef0fe
S
4092 di<<" R.A.Z de tous les modes de selecion"<<"\n";
4093 di<<" Fermeture du Context local"<<"\n";
7fd59977 4094 if (TheAISContext()->HasOpenedContext())
4095 TheAISContext()->CloseLocalContext();
4096 }
7fd59977 4097 }
4098
7fd59977 4099 // IL n'y a aps de nom de shape passe en argument
4100 if (HaveToSet && !ThereIsName){
91322f44 4101 Standard_Integer aMode=Draw::Atoi(argv [1]);
7fd59977 4102
4103 const char *cmode="???";
7fd59977 4104 switch (aMode) {
4105 case 0: cmode = "Shape"; break;
4106 case 1: cmode = "Vertex"; break;
4107 case 2: cmode = "Edge"; break;
4108 case 3: cmode = "Wire"; break;
4109 case 4: cmode = "Face"; break;
4110 case 5: cmode = "Shell"; break;
4111 case 6: cmode = "Solid"; break;
4112 case 7: cmode = "Compound"; break;
4113 }
4114
4115 if( !TheAISContext()->HasOpenedContext() ) {
5cbef0fe
S
4116 // il n'y a pas de Context local d'ouvert
4117 // on en ouvre un et on charge toutes les shapes displayees
4118 // on load tous les objets displayees et on Activate les objets de la liste
4119 AIS_ListOfInteractive ListOfIO;
4120 // on sauve dans une AISListOfInteractive tous les objets currents
c3282ec1 4121 if (TheAISContext()->NbSelected()>0 ){
4122 TheAISContext()->UnhilightSelected(Standard_False);
5cbef0fe 4123
c3282ec1 4124 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
4125 ListOfIO.Append(TheAISContext()->SelectedInteractive() );
7fd59977 4126 }
4127 }
4128
4129 TheAISContext()->OpenLocalContext(Standard_False);
4130 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4131 it (GetMapOfAIS());
4132 while(it.More()){
4133 Handle(AIS_InteractiveObject) aIO =
4134 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4135 if (!aIO.IsNull())
4136 TheAISContext()->Load(aIO,0,Standard_False);
4137 it.Next();
4138 }
4139 // traitement des objets qui etaient currents dans le Contexte global
4140 if (!ListOfIO.IsEmpty() ) {
4141 // il y avait des objets currents
4142 AIS_ListIteratorOfListOfInteractive iter;
4143 for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) {
4144 Handle(AIS_InteractiveObject) aIO=iter.Value();
4145 TheAISContext()->Activate(aIO,aMode);
4146 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4147 }
4148 }
4149 else {
4150 // On applique le mode a tous les objets displayes
4151 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4152 it2 (GetMapOfAIS());
4153 while(it2.More()){
4154 Handle(AIS_InteractiveObject) aIO =
4155 Handle(AIS_InteractiveObject)::DownCast(it2.Key1());
4156 if (!aIO.IsNull()) {
4157 di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n";
4158 TheAISContext()->Activate(aIO,aMode);
4159 }
4160 it2.Next();
4161 }
4162 }
4163
4164 }
4165
4166 else {
4167 // un Context local est deja ouvert
4168 // Traitement des objets du Context local
4169 if (TheAISContext()->NbSelected()>0 ){
4170 TheAISContext()->UnhilightSelected(Standard_False);
4171 // il y a des objets selected,on les parcourt
4172 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){
c3282ec1 4173 Handle(AIS_InteractiveObject) aIO=TheAISContext()->SelectedInteractive();
7fd59977 4174
4175
4176 if (HaveMode(aIO,aMode) ) {
4177 di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4178 TheAISContext()->Deactivate(aIO,aMode);
4179 }
4180 else{
4181 di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4182 TheAISContext()->Activate(aIO,aMode);
4183 }
4184
4185 }
4186 }
4187 else{
4188 // il n'y a pas d'objets selected
4189 // tous les objets diplayes sont traites
4190 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName
4191 it (GetMapOfAIS());
4192 while(it.More()){
4193 Handle(AIS_InteractiveObject) aIO =
4194 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4195 if (!aIO.IsNull()) {
4196 if (HaveMode(aIO,aMode) ) {
4197 di<<" Mode: "<<cmode<<" OFF pour "
4198 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4199 TheAISContext()->Deactivate(aIO,aMode);
4200 }
4201 else{
4202 di<<" Mode: "<<cmode<<" ON pour"
4203 <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n";
4204 TheAISContext()->Activate(aIO,aMode);
4205 }
4206 }
4207 it.Next();
4208 }
4209 }
4210 }
4211 }
4212 else if (HaveToSet && ThereIsName){
91322f44 4213 Standard_Integer aMode=Draw::Atoi(argv [2]);
7fd59977 4214 Handle(AIS_InteractiveObject) aIO =
4215 Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
4216
4217 if (!aIO.IsNull()) {
4218 const char *cmode="???";
4219
4220 switch (aMode) {
4221 case 0: cmode = "Shape"; break;
4222 case 1: cmode = "Vertex"; break;
4223 case 2: cmode = "Edge"; break;
4224 case 3: cmode = "Wire"; break;
4225 case 4: cmode = "Face"; break;
4226 case 5: cmode = "Shell"; break;
4227 case 6: cmode = "Solid"; break;
4228 case 7: cmode = "Compound"; break;
4229 }
4230
4231 if( !TheAISContext()->HasOpenedContext() ) {
4232 TheAISContext()->OpenLocalContext(Standard_False);
4233 // On charge tous les objets de la map
4234 ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS());
4235 while(it.More()){
4236 Handle(AIS_InteractiveObject) aShape=
4237 Handle(AIS_InteractiveObject)::DownCast(it.Key1());
4238 if (!aShape.IsNull())
4239 TheAISContext()->Load(aShape,0,Standard_False);
4240 it.Next();
4241 }
4242 TheAISContext()->Activate(aIO,aMode);
4243 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4244 }
4245
4246 else {
4247 // un Context local est deja ouvert
4248 if (HaveMode(aIO,aMode) ) {
4249 di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n";
4250 TheAISContext()->Deactivate(aIO,aMode);
4251 }
4252 else{
4253 di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n";
4254 TheAISContext()->Activate(aIO,aMode);
4255 }
4256 }
4257 }
4258 }
4259 }
4260 return 0;
7fd59977 4261}
4262
cb78155f 4263//! Auxiliary method to print Interactive Object information
4264static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected,
4265 const Handle(Standard_Transient)& theObject,
4266 Draw_Interpretor& theDI)
4267{
4268 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject);
4269 if (anObj.IsNull())
4270 {
4271 theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n";
4272 return;
4273 }
7fd59977 4274
cb78155f 4275 theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ")
4276 << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ")
4277 << (theDetected.Contains (anObj) ? " Detected" : " ")
4278 << " Type: ";
4279 if (anObj->Type() == AIS_KOI_Datum)
4280 {
4281 // AIS_Datum
4282 if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; }
4283 else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; }
4284 else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; }
4285 else if (anObj->Signature() == 5) { theDI << " AIS_Line"; }
4286 else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; }
4287 else if (anObj->Signature() == 1) { theDI << " AIS_Point"; }
4288 else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; }
7fd59977 4289 }
4290 // AIS_Shape
cb78155f 4291 else if (anObj->Type() == AIS_KOI_Shape
4292 && anObj->Signature() == 0)
4293 {
4294 theDI << " AIS_Shape";
7fd59977 4295 }
cb78155f 4296 else if (anObj->Type() == AIS_KOI_Relation)
4297 {
4298 // AIS_Dimention and AIS_Relation
4299 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj);
4300 switch (aRelation->KindOfDimension())
4301 {
4302 case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break;
4303 case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break;
4304 case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break;
4305 case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break;
4306 //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break;
4307 case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break;
4308 case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break;
4309 default: theDI << " UNKNOWN dimension"; break;
4310 }
4311 }
4312 else
4313 {
4314 theDI << " UserPrs";
4315 }
4316 theDI << " (" << theObject->DynamicType()->Name() << ")";
7fd59977 4317}
4318
cb78155f 4319//! Print information about locally selected sub-shapes
4320static void localCtxInfo (Draw_Interpretor& theDI)
4321{
4322 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4323 if (!aCtx->HasOpenedContext())
4324 {
4325 return;
4326 }
7fd59977 4327
cb78155f 4328 TCollection_AsciiString aPrevName;
4329 Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext();
4330 for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected())
4331 {
4332 const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape();
4333 const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive());
4334 if (aSubShape.IsNull()
4335 || aShapeIO.IsNull()
4336 || !GetMapOfAIS().IsBound1 (aShapeIO))
4337 {
4338 continue;
4339 }
4340
4341 const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO);
4342 TopTools_MapOfShape aFilter;
4343 Standard_Integer aNumber = 0;
4344 const TopoDS_Shape aShape = aShapeIO->Shape();
4345 for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType());
4346 anIter.More(); anIter.Next())
4347 {
4348 if (!aFilter.Add (anIter.Current()))
4349 {
4350 continue; // filter duplicates
4351 }
4352
4353 ++aNumber;
4354 if (!anIter.Current().IsSame (aSubShape))
4355 {
4356 continue;
4357 }
4358
4359 Standard_CString aShapeName = NULL;
4360 switch (aSubShape.ShapeType())
4361 {
4362 case TopAbs_COMPOUND: aShapeName = " Compound"; break;
4363 case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break;
4364 case TopAbs_SOLID: aShapeName = " Solid"; break;
4365 case TopAbs_SHELL: aShapeName = " Shell"; break;
4366 case TopAbs_FACE: aShapeName = " Face"; break;
4367 case TopAbs_WIRE: aShapeName = " Wire"; break;
4368 case TopAbs_EDGE: aShapeName = " Edge"; break;
4369 case TopAbs_VERTEX: aShapeName = " Vertex"; break;
4370 default:
4371 case TopAbs_SHAPE: aShapeName = " Shape"; break;
4372 }
4373
4374 if (aParentName != aPrevName)
4375 {
4376 theDI << "Locally selected sub-shapes within " << aParentName << ":\n";
4377 aPrevName = aParentName;
4378 }
4379 theDI << " " << aShapeName << " #" << aNumber << "\n";
4380 break;
4381 }
4382 }
4383}
7fd59977 4384
4385//==============================================================================
4386//function : VState
4387//purpose :
7fd59977 4388//==============================================================================
cb78155f 4389static Standard_Integer VState (Draw_Interpretor& theDI,
4390 Standard_Integer theArgNb,
4391 Standard_CString* theArgVec)
7fd59977 4392{
cb78155f 4393 Handle(AIS_InteractiveContext) aCtx = TheAISContext();
4394 if (aCtx.IsNull())
4395 {
4396 std::cerr << "Error: No opened viewer!\n";
4397 return 1;
7fd59977 4398 }
cb78155f 4399
51023771 4400 Standard_Boolean toPrintEntities = Standard_False;
4401 Standard_Boolean toCheckSelected = Standard_False;
4402
4403 for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx)
4404 {
4405 TCollection_AsciiString anOption (theArgVec[anArgIdx]);
4406 anOption.LowerCase();
4407 if (anOption == "-detectedentities"
4408 || anOption == "-entities")
4409 {
4410 toPrintEntities = Standard_True;
4411 }
4412 else if (anOption == "-hasselected")
4413 {
4414 toCheckSelected = Standard_True;
4415 }
4416 }
4417
4418 if (toCheckSelected)
4419 {
4420 aCtx->InitSelected();
4421 TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape()));
4422 theDI << "Check if context has selected shape: " << hasSelected << "\n";
4423
4424 return 0;
4425 }
4426
4427 if (toPrintEntities)
8e7c8ccf 4428 {
4429 theDI << "Detected entities:\n";
4430 Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector();
f751596e 4431 for (aSelector->InitDetected(); aSelector->MoreDetected(); aSelector->NextDetected())
8e7c8ccf 4432 {
f751596e 4433 const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->DetectedEntity();
8e7c8ccf 4434 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
4435 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3bf9a45f 4436 SelectMgr_SelectingVolumeManager aMgr =
4437 anObj->HasTransformation() ? aSelector->GetManager().ScaleAndTransform (1, anObj->InversedTransformation())
4438 : aSelector->GetManager();
f751596e 4439 SelectBasics_PickResult aResult;
4440 anEntity->Matches (aMgr, aResult);
3bf9a45f 4441 gp_Pnt aDetectedPnt = aMgr.DetectedPoint (aResult.Depth());
8e7c8ccf 4442
4443 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4444 aName.LeftJustify (20, ' ');
4445 char anInfoStr[512];
f751596e 4446 Sprintf (anInfoStr,
4447 " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f",
4448 aResult.Depth(),
4449 aResult.DistToGeomCenter(),
3bf9a45f 4450 aDetectedPnt.X(), aDetectedPnt.Y(), aDetectedPnt.Z());
8e7c8ccf 4451 theDI << " " << aName
4452 << anInfoStr
4453 << " (" << anEntity->DynamicType()->Name() << ")"
4454 << "\n";
4455
4456 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
4457 if (!aBRepOwner.IsNull())
4458 {
4459 theDI << " Detected Shape: "
4460 << aBRepOwner->Shape().TShape()->DynamicType()->Name()
4461 << "\n";
4462 }
4463
4464 Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity);
4465 if (!aWire.IsNull())
4466 {
4467 Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected();
4468 theDI << " Detected Child: "
4469 << aSen->DynamicType()->Name()
4470 << "\n";
4471 }
4472 }
4473 return 0;
4474 }
4475
cb78155f 4476 NCollection_Map<Handle(AIS_InteractiveObject)> aDetected;
4477 for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected())
4478 {
4479 aDetected.Add (aCtx->DetectedCurrentObject());
4480 }
4481
4482 const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*');
4483 if (theArgNb >= 2
4484 && !toShowAll)
4485 {
4486 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
7fd59977 4487 {
cb78155f 4488 const TCollection_AsciiString anObjName = theArgVec[anArgIter];
4489 if (!GetMapOfAIS().IsBound2 (anObjName))
4490 {
4491 theDI << anObjName << " doesn't exist!\n";
4492 continue;
7fd59977 4493 }
4494
cb78155f 4495 const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName);
4496 TCollection_AsciiString aName = anObjName;
4497 aName.LeftJustify (20, ' ');
4498 theDI << " " << aName << " ";
4499 objInfo (aDetected, anObjTrans, theDI);
4500 theDI << "\n";
7fd59977 4501 }
cb78155f 4502 return 0;
7fd59977 4503 }
cb78155f 4504
c3282ec1 4505 if (aCtx->NbSelected() > 0
cb78155f 4506 && !toShowAll)
4507 {
c3282ec1 4508 for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
cb78155f 4509 {
c3282ec1 4510 Handle(AIS_InteractiveObject) anObj = aCtx->SelectedInteractive();
cb78155f 4511 TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
4512 aName.LeftJustify (20, ' ');
4513 theDI << aName << " ";
4514 objInfo (aDetected, anObj, theDI);
4515 theDI << "\n";
7fd59977 4516 }
cb78155f 4517 return 0;
7fd59977 4518 }
4519
cb78155f 4520 theDI << "Neutral-point state:\n";
4521 for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS());
4522 anObjIter.More(); anObjIter.Next())
4523 {
4524 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1());
4525 if (anObj.IsNull())
4526 {
4527 continue;
4528 }
4529
4530 TCollection_AsciiString aName = anObjIter.Key2();
4531 aName.LeftJustify (20, ' ');
4532 theDI << " " << aName << " ";
4533 objInfo (aDetected, anObj, theDI);
4534 theDI << "\n";
4535 }
4536 localCtxInfo (theDI);
7fd59977 4537 return 0;
4538}
4539
7fd59977 4540//=======================================================================
4541//function : PickObjects
4542//purpose :
4543//=======================================================================
4544Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr,
4545 const AIS_KindOfInteractive TheType,
4546 const Standard_Integer TheSignature,
4547 const Standard_Integer MaxPick)
4548{
4549 Handle(AIS_InteractiveObject) IO;
4550 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4551
4552 // step 1: prepare the data
4952a30a 4553 if(curindex !=0){
7fd59977 4554 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4555 TheAISContext()->AddFilter(F1);
4556 }
4557
4558 // step 2 : wait for the selection...
4559// Standard_Boolean IsGood (Standard_False);
4560// Standard_Integer NbPick(0);
4561 Standard_Boolean NbPickGood (0),NbToReach(arr->Length());
4562 Standard_Integer NbPickFail(0);
4563 Standard_Integer argccc = 5;
4564 const char *bufff[] = { "A", "B", "C","D", "E" };
4565 const char **argvvv = (const char **) bufff;
4566
4567
4568 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4569 while(ViewerMainLoop(argccc,argvvv)){}
4570 Standard_Integer NbStored = TheAISContext()->NbSelected();
4571 if((unsigned int ) NbStored != NbPickGood)
4572 NbPickGood= NbStored;
4573 else
4574 NbPickFail++;
4575 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl;
4576 }
4577
4578 // step3 get result.
4579
4580 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4581
4582 Standard_Integer i(0);
4583 for(TheAISContext()->InitSelected();
4584 TheAISContext()->MoreSelected();
4585 TheAISContext()->NextSelected()){
4586 i++;
4587 Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive();
4588 arr->SetValue(i,IO2);
4589 }
4590
4591
4592 if(curindex>0)
4593 TheAISContext()->CloseLocalContext(curindex);
4594
4595 return Standard_True;
4596}
4597
4598
4599//=======================================================================
4600//function : PickObject
4601//purpose :
4602//=======================================================================
4603Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType,
4604 const Standard_Integer TheSignature,
4605 const Standard_Integer MaxPick)
4606{
4607 Handle(AIS_InteractiveObject) IO;
4608 Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext();
4609
4610 // step 1: prepare the data
4611
4952a30a 4612 if(curindex !=0){
7fd59977 4613 Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature);
4614 TheAISContext()->AddFilter(F1);
4615 }
4616
4617 // step 2 : wait for the selection...
4618 Standard_Boolean IsGood (Standard_False);
4619 Standard_Integer NbPick(0);
4620 Standard_Integer argccc = 5;
4621 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4622 const char **argvvv = (const char **) bufff;
4623
4624
4625 while(!IsGood && NbPick<= MaxPick){
4626 while(ViewerMainLoop(argccc,argvvv)){}
4627 IsGood = (TheAISContext()->NbSelected()>0) ;
4628 NbPick++;
4629 cout<<"Nb Pick :"<<NbPick<<endl;
4630 }
4631
4632
4633 // step3 get result.
4634 if(IsGood){
4635 TheAISContext()->InitSelected();
4636 IO = TheAISContext()->SelectedInteractive();
4637 }
4638
4952a30a 4639 if(curindex!=0)
7fd59977 4640 TheAISContext()->CloseLocalContext(curindex);
4641 return IO;
4642}
4643
4644//=======================================================================
4645//function : PickShape
4646//purpose : First Activate the rightmode + Put Filters to be able to
4647// pick objets that are of type <TheType>...
4648//=======================================================================
4649
4650TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType,
4651 const Standard_Integer MaxPick)
4652{
4653
4654 // step 1: prepare the data
4655
4656 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4657 TopoDS_Shape result;
4658
4659 if(TheType==TopAbs_SHAPE){
4660 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4661 TheAISContext()->AddFilter(F1);
4662 }
4663 else{
4664 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4665 TheAISContext()->AddFilter(TF);
4666 TheAISContext()->ActivateStandardMode(TheType);
4667
4668 }
4669
4670
4671 // step 2 : wait for the selection...
4672 Standard_Boolean NoShape (Standard_True);
4673 Standard_Integer NbPick(0);
4674 Standard_Integer argccc = 5;
4675 const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
4676 const char **argvvv = (const char **) bufff;
4677
4678
4679 while(NoShape && NbPick<= MaxPick){
4680 while(ViewerMainLoop(argccc,argvvv)){}
4681 NoShape = (TheAISContext()->NbSelected()==0) ;
4682 NbPick++;
4683 cout<<"Nb Pick :"<<NbPick<<endl;
4684 }
4685
4686 // step3 get result.
4687
4688 if(!NoShape){
4689
4690 TheAISContext()->InitSelected();
4691 if(TheAISContext()->HasSelectedShape())
4692 result = TheAISContext()->SelectedShape();
4693 else{
4694 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
c5f3a425 4695 result = Handle(AIS_Shape)::DownCast (IO)->Shape();
7fd59977 4696 }
4697 }
4698
4699 if(curindex>0)
4700 TheAISContext()->CloseLocalContext(curindex);
4701
4702 return result;
4703}
4704
4705
4706//=======================================================================
4707//function : PickShapes
4708//purpose :
4709//=======================================================================
4710Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType,
4711 Handle(TopTools_HArray1OfShape)& thearr,
4712 const Standard_Integer MaxPick)
4713{
4714
4715 Standard_Integer Taille = thearr->Length();
4716 if(Taille>1)
4717 cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n";
4718
4719 // step 1: prepare the data
4720 Standard_Integer curindex = TheAISContext()->OpenLocalContext();
4721 if(TheType==TopAbs_SHAPE){
4722 Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape);
4723 TheAISContext()->AddFilter(F1);
4724 }
4725 else{
4726 Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType);
4727 TheAISContext()->AddFilter(TF);
4728 TheAISContext()->ActivateStandardMode(TheType);
4729
4730 }
4731
4732 // step 2 : wait for the selection...
4733
4734 Standard_Boolean NbPickGood (0),NbToReach(thearr->Length());
4735 Standard_Integer NbPickFail(0);
4736 Standard_Integer argccc = 5;
4737 const char *bufff[] = { "A", "B", "C","D", "E" };
4738 const char **argvvv = (const char **) bufff;
4739
4740
4741 while(NbPickGood<NbToReach && NbPickFail <= MaxPick){
4742 while(ViewerMainLoop(argccc,argvvv)){}
4743 Standard_Integer NbStored = TheAISContext()->NbSelected();
4744 if((unsigned int ) NbStored != NbPickGood)
4745 NbPickGood= NbStored;
4746 else
4747 NbPickFail++;
4748 cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n";
4749 }
4750
4751 // step3 get result.
4752
4753 if((unsigned int ) NbPickFail >= NbToReach) return Standard_False;
4754
4755 Standard_Integer i(0);
4756 for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){
4757 i++;
4758 if(TheAISContext()->HasSelectedShape())
4759 thearr->SetValue(i,TheAISContext()->SelectedShape());
4760 else{
4761 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
c5f3a425 4762 thearr->SetValue(i,Handle(AIS_Shape)::DownCast (IO)->Shape());
7fd59977 4763 }
4764 }
4765
4766 TheAISContext()->CloseLocalContext(curindex);
4767 return Standard_True;
4768}
4769
4770
4771//=======================================================================
4772//function : VPickShape
4773//purpose :
4774//=======================================================================
4775static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv)
4776{
4777 TopoDS_Shape PickSh;
4778 TopAbs_ShapeEnum theType = TopAbs_COMPOUND;
4779
4780 if(argc==1)
4781 theType = TopAbs_SHAPE;
4782 else{
4783 if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX;
4784 else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE;
4785 else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE;
4786 else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE;
4787 else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE;
4788 else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL;
4789 else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID;
4790 }
4791
4792 static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0};
4793 static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"};
4794
4795 TCollection_AsciiString name;
4796
4797
4798 Standard_Integer NbToPick = argc>2 ? argc-2 : 1;
4799 if(NbToPick==1){
4800 PickSh = ViewerTest::PickShape(theType);
4801
4802 if(PickSh.IsNull())
4803 return 1;
4804 if(argc>2){
4805 name += argv[2];
4806 }
4807 else{
4808
4809 if(!PickSh.IsNull()){
4810 nbOfSub[Standard_Integer(theType)]++;
4811 name += "Picked_";
4812 name += nameType[Standard_Integer(theType)];
4813 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4814 name +="_";
4815 name+=indxstring;
4816 }
4817 }
4818 // si on avait une petite methode pour voir si la shape
4819 // est deja dans la Double map, ca eviterait de creer....
4820 DBRep::Set(name.ToCString(),PickSh);
4821
4822 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4823 GetMapOfAIS().Bind(newsh, name);
4824 TheAISContext()->Display(newsh);
4825 di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n";
4826 }
4827
4828 // Plusieurs objets a picker, vite vite vite....
4829 //
4830 else{
4831 Standard_Boolean autonaming = !strcasecmp(argv[2],".");
4832 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
4833 if(ViewerTest::PickShapes(theType,arr)){
4834 for(Standard_Integer i=1;i<=NbToPick;i++){
4835 PickSh = arr->Value(i);
4836 if(!PickSh.IsNull()){
4837 if(autonaming){
4838 nbOfSub[Standard_Integer(theType)]++;
4839 name.Clear();
4840 name += "Picked_";
4841 name += nameType[Standard_Integer(theType)];
4842 TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]);
4843 name +="_";
4844 name+=indxstring;
4845 }
4846 }
4847 else
4848 name = argv[1+i];
4849
4850 DBRep::Set(name.ToCString(),PickSh);
4851 Handle(AIS_Shape) newsh = new AIS_Shape(PickSh);
4852 GetMapOfAIS().Bind(newsh, name);
4853 di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n";
4854 TheAISContext()->Display(newsh);
4855
4856 }
4857 }
4858 }
4859 return 0;
7fd59977 4860}
7fd59977 4861
d8110103 4862//=======================================================================
4863//function : VPickSelected
4864//purpose :
4865//=======================================================================
4866static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs)
4867{
4868 static Standard_Integer aCount = 0;
4869 TCollection_AsciiString aName = "PickedShape_";
4870
4871 if (theArgNb > 1)
4872 {
4873 aName = theArgs[1];
4874 }
4875 else
4876 {
4877 aName = aName + aCount++ + "_";
4878 }
4879
4880 Standard_Integer anIdx = 0;
4881 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx)
4882 {
4883 TopoDS_Shape aShape;
4884 if (TheAISContext()->HasSelectedShape())
4885 {
4886 aShape = TheAISContext()->SelectedShape();
4887 }
4888 else
4889 {
4890 Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive();
c5f3a425 4891 aShape = Handle(AIS_Shape)::DownCast (IO)->Shape();
d8110103 4892 }
4893
4894 TCollection_AsciiString aCurrentName = aName;
4895 if (anIdx > 0)
4896 {
4897 aCurrentName += anIdx;
4898 }
4899
4900 DBRep::Set ((aCurrentName).ToCString(), aShape);
4901
4902 Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape);
4903 GetMapOfAIS().Bind (aNewShape, aCurrentName);
4904 TheAISContext()->Display (aNewShape);
4905 }
4906
4907 return 0;
4908}
4909
7fd59977 4910//=======================================================================
4911//function : list of known objects
4912//purpose :
4913//=======================================================================
4914static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** )
4915{
4916 // 1234567890 12345678901234567 123456789
4917 TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"};
4918 TCollection_AsciiString BlankLine(64,'_');
4919 Standard_Integer i ;
4920
4921 di<<"/n"<<BlankLine.ToCString()<<"\n";
4922
4923 for( i =0;i<=2;i++)
4924 Colum[i].Center(20,' ');
4925 for(i=0;i<=2;i++)
4926 di<<"|"<<Colum[i].ToCString();
4927 di<<"|"<<"\n";
4928
4929 di<<BlankLine.ToCString()<<"\n";
4930
4931 // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"};
4932 const char ** names = GetTypeNames();
4933
4934 TCollection_AsciiString curstring;
4935 TCollection_AsciiString curcolum[3];
4936
4937
4938 // les objets de type Datum..
4939 curcolum[1]+="Datum";
4940 for(i =0;i<=6;i++){
4941 curcolum[0].Clear();
4942 curcolum[0] += names[i];
4943
4944 curcolum[2].Clear();
4945 curcolum[2]+=TCollection_AsciiString(i+1);
4946
4947 for(Standard_Integer j =0;j<=2;j++){
4948 curcolum[j].Center(20,' ');
4949 di<<"|"<<curcolum[j].ToCString();
4950 }
4951 di<<"|"<<"\n";
4952 }
4953 di<<BlankLine.ToCString()<<"\n";
4954
4955 // les objets de type shape
4956 curcolum[1].Clear();
4957 curcolum[1]+="Shape";
4958 curcolum[1].Center(20,' ');
4959
4960 for(i=0;i<=2;i++){
4961 curcolum[0].Clear();
4962 curcolum[0] += names[7+i];
4963 curcolum[2].Clear();
4964 curcolum[2]+=TCollection_AsciiString(i);
4965
4966 for(Standard_Integer j =0;j<=2;j++){
4967 curcolum[j].Center(20,' ');
4968 di<<"|"<<curcolum[j].ToCString();
4969 }
4970 di<<"|"<<"\n";
4971 }
4972 di<<BlankLine.ToCString()<<"\n";
4973 // les IO de type objet...
4974 curcolum[1].Clear();
4975 curcolum[1]+="Object";
4976 curcolum[1].Center(20,' ');
4977 for(i=0;i<=1;i++){
4978 curcolum[0].Clear();
4979 curcolum[0] += names[10+i];
4980 curcolum[2].Clear();
4981 curcolum[2]+=TCollection_AsciiString(i);
4982
4983 for(Standard_Integer j =0;j<=2;j++){
4984 curcolum[j].Center(20,' ');
4985 di<<"|"<<curcolum[j].ToCString();
4986 }
4987 di<<"|"<<"\n";
4988 }
4989 di<<BlankLine.ToCString()<<"\n";
4990 // les contraintes et dimensions.
4991 // pour l'instant on separe juste contraintes et dimensions...
4992 // plus tard, on detaillera toutes les sortes...
4993 curcolum[1].Clear();
4994 curcolum[1]+="Relation";
4995 curcolum[1].Center(20,' ');
4996 for(i=0;i<=1;i++){
4997 curcolum[0].Clear();
4998 curcolum[0] += names[12+i];
4999 curcolum[2].Clear();
5000 curcolum[2]+=TCollection_AsciiString(i);
5001
5002 for(Standard_Integer j =0;j<=2;j++){
5003 curcolum[j].Center(20,' ');
5004 di<<"|"<<curcolum[j].ToCString();
5005 }
5006 di<<"|"<<"\n";
5007 }
5008 di<<BlankLine.ToCString()<<"\n";
5009
5010
5011 return 0;
5012}
5013
5014
5015static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv)
5016{
4952a30a 5017 if(argc!=2) return 1;
7fd59977 5018
5019 AIS_KindOfInteractive TheType;
5020 Standard_Integer TheSign(-1);
5021 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5022
5023
5024 AIS_ListOfInteractive LIO;
5025
5026 // en attendant l'amelioration ais pour les dimensions...
5027 //
5028 Standard_Integer dimension_status(-1);
5029 if(TheType==AIS_KOI_Relation){
5030 dimension_status = TheSign ==1 ? 1 : 0;
5031 TheSign=-1;
5032 }
5033
5034 TheAISContext()->DisplayedObjects(TheType,TheSign,LIO);
5035 Handle(AIS_InteractiveObject) curio;
5036 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5037 curio = it.Value();
5038
5039 if(dimension_status == -1)
5040 TheAISContext()->Erase(curio,Standard_False);
5041 else {
c5f3a425 5042 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
7fd59977 5043 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5044 (dimension_status==1 && KOD != AIS_KOD_NONE))
5045 TheAISContext()->Erase(curio,Standard_False);
5046 }
5047 }
5048 TheAISContext()->UpdateCurrentViewer();
5049 return 0;
5050}
5051static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv)
5052{
5053 if(argc!=2) return 1;
5054
5055 AIS_KindOfInteractive TheType;
5056 Standard_Integer TheSign(-1);
5057 GetTypeAndSignfromString(argv[1],TheType,TheSign);
5058
5059 // en attendant l'amelioration ais pour les dimensions...
5060 //
5061 Standard_Integer dimension_status(-1);
5062 if(TheType==AIS_KOI_Relation){
5063 dimension_status = TheSign ==1 ? 1 : 0;
5064 TheSign=-1;
5065 }
5066
5067 AIS_ListOfInteractive LIO;
5068 TheAISContext()->ObjectsInside(LIO,TheType,TheSign);
5069 Handle(AIS_InteractiveObject) curio;
5070 for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){
5071 curio = it.Value();
5072 if(dimension_status == -1)
5073 TheAISContext()->Display(curio,Standard_False);
5074 else {
c5f3a425 5075 AIS_KindOfDimension KOD = Handle(AIS_Relation)::DownCast (curio)->KindOfDimension();
7fd59977 5076 if ((dimension_status==0 && KOD == AIS_KOD_NONE)||
5077 (dimension_status==1 && KOD != AIS_KOD_NONE))
5078 TheAISContext()->Display(curio,Standard_False);
5079 }
5080
5081 }
5082
5083 TheAISContext()->UpdateCurrentViewer();
5084 return 0;
5085}
5086
7fd59977 5087static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a)
5088{
5089 ifstream s(a[1]);
5090 BRep_Builder builder;
5091 TopoDS_Shape shape;
5092 BRepTools::Read(shape, s, builder);
5093 DBRep::Set(a[1], shape);
5094 Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
5095 Handle(AIS_Shape) ais = new AIS_Shape(shape);
5096 Ctx->Display(ais);
5097 return 0;
5098}
7fd59977 5099
189f85a3 5100//===============================================================================================
5101//function : VBsdf
5102//purpose :
5103//===============================================================================================
5104static int VBsdf (Draw_Interpretor& theDi,
5105 Standard_Integer theArgsNb,
5106 const char** theArgVec)
5107{
5108 Handle(V3d_View) aView = ViewerTest::CurrentView();
5109 Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
5110 if (aView.IsNull()
5111 || aViewer.IsNull())
5112 {
5113 std::cerr << "No active viewer!\n";
5114 return 1;
5115 }
5116
5117 ViewerTest_CmdParser aCmd;
5118
5119 aCmd.AddDescription ("Adjusts parameters of material BSDF:");
5120 aCmd.AddOption ("print|echo|p", "Print BSDF");
5121
5122 aCmd.AddOption ("kd", "Weight of the Lambertian BRDF");
5123 aCmd.AddOption ("kr", "Weight of the reflection BRDF");
5124 aCmd.AddOption ("kt", "Weight of the transmission BTDF");
5125 aCmd.AddOption ("ks", "Weight of the glossy Blinn BRDF");
5126 aCmd.AddOption ("le", "Self-emitted radiance");
5127
5128 aCmd.AddOption ("fresnel|f", "Fresnel coefficients; Allowed fresnel formats are: Constant x, Schlick x y z, Dielectric x, Conductor x y");
5129
5130 aCmd.AddOption ("roughness|r", "Roughness of material (Blinn's exponent)");
5131 aCmd.AddOption ("absorpCoeff|af", "Absorption coeff (only for transparent material)");
5132 aCmd.AddOption ("absorpColor|ac", "Absorption color (only for transparent material)");
5133
5134 aCmd.AddOption ("normalize|n", "Normalize BSDF coefficients");
5135
5136 aCmd.Parse (theArgsNb, theArgVec);
5137
5138 if (aCmd.HasOption ("help"))
5139 {
5140 theDi.PrintHelp (theArgVec[0]);
5141 return 0;
5142 }
5143
5144 TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
5145
5146 // find object
5147 ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
5148 if (!aMap.IsBound2 (aName) )
5149 {
5150 std::cerr << "Use 'vdisplay' before" << "\n";
5151 return 1;
5152 }
5153
5154 Handle(AIS_InteractiveObject) anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName));
5155 Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material();
5156 Graphic3d_BSDF aBSDF = aMaterial.BSDF();
5157
5158 if (aCmd.HasOption ("print"))
5159 {
5160 Graphic3d_Vec4 aFresnel = aBSDF.Fresnel.Serialize();
5161
5162 std::cout << "\n"
5163 << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n"
5164 << "Kr: " << aBSDF.Kr.r() << ", " << aBSDF.Kr.g() << ", " << aBSDF.Kr.b() << "\n"
5165 << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n"
5166 << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n"
5167 << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"
5168 << "Fresnel: ";
5169
5170 if (aFresnel.x() >= 0.f)
5171 {
5172 std::cout
5173 << "|Schlick| " << aFresnel.x() << ", " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5174 }
5175 else if (aFresnel.x() >= -1.5f)
5176 {
5177 std::cout
5178 << "|Constant| " << aFresnel.z() << "\n";
5179 }
5180 else if (aFresnel.x() >= -2.5f)
5181 {
5182 std::cout
5183 << "|Conductor| " << aFresnel.y() << ", " << aFresnel.z() << "\n";
5184 }
5185 else
5186 {
5187 std::cout
5188 << "|Dielectric| " << aFresnel.y() << "\n";
5189 }
5190
5191
5192 std::cout
5193 << "Roughness: " << aBSDF.Roughness << "\n"
5194 << "Absorption coeff: " << aBSDF.AbsorptionCoeff << "\n"
5195 << "Absorption color: " << aBSDF.AbsorptionColor.r() << ", "
5196 << aBSDF.AbsorptionColor.g() << ", "
5197 << aBSDF.AbsorptionColor.b() << "\n";
5198
5199 return 0;
5200 }
5201
5202 if (aCmd.HasOption ("roughness", 1, Standard_True))
5203 {
5204 aCmd.Arg ("roughness", 0);
5205 aBSDF.Roughness = aCmd.ArgFloat ("roughness");
5206 }
5207
5208 if (aCmd.HasOption ("absorpCoeff", 1, Standard_True))
5209 {
5210 aBSDF.AbsorptionCoeff = aCmd.ArgFloat ("absorpCoeff");
5211 }
5212
5213 if (aCmd.HasOption ("absorpColor", 3, Standard_True))
5214 {
5215 aBSDF.AbsorptionColor = aCmd.ArgVec3f ("absorpColor");
5216 }
5217
5218 if (aCmd.HasOption ("kd", 3))
5219 {
5220 aBSDF.Kd = aCmd.ArgVec3f ("kd");
5221 }
5222 else if (aCmd.HasOption ("kd", 1, Standard_True))
5223 {
5224 aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd"));
5225 }
5226
5227 if (aCmd.HasOption ("kr", 3))
5228 {
5229 aBSDF.Kr = aCmd.ArgVec3f ("kr");
5230 }
5231 else if (aCmd.HasOption ("kr", 1, Standard_True))
5232 {
5233 aBSDF.Kr = Graphic3d_Vec3 (aCmd.ArgFloat ("kr"));
5234 }
5235
5236 if (aCmd.HasOption ("kt", 3))
5237 {
5238 aBSDF.Kt = aCmd.ArgVec3f ("kt");
5239 }
5240 else if (aCmd.HasOption ("kt", 1, Standard_True))
5241 {
5242 aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt"));
5243 }
5244
5245 if (aCmd.HasOption ("ks", 3))
5246 {
5247 aBSDF.Ks = aCmd.ArgVec3f ("ks");
5248 }
5249 else if (aCmd.HasOption ("ks", 1, Standard_True))
5250 {
5251 aBSDF.Ks = Graphic3d_Vec3 (aCmd.ArgFloat ("ks"));
5252 }
5253
5254 if (aCmd.HasOption ("le", 3))
5255 {
5256 aBSDF.Le = aCmd.ArgVec3f ("le");
5257 }
5258 else if (aCmd.HasOption ("le", 1, Standard_True))
5259 {
5260 aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le"));
5261 }
5262
5263 const std::string aFresnelErrorMessage =
5264 "Error! Wrong Fresnel type. Allowed types are: Constant x, Schlick x y z, Dielectric x, Conductor x y.\n";
5265
5266 if (aCmd.HasOption ("fresnel", 4)) // Schlick: type, x, y ,z
5267 {
5268 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5269 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5270
5271 if (aFresnelType == "schlick")
5272 {
5273 aBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (
5274 Graphic3d_Vec3 (static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5275 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())),
5276 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 3).c_str()))));
5277 }
5278 else
5279 {
5280 std::cout << aFresnelErrorMessage;
5281 }
5282 }
5283 else if (aCmd.HasOption ("fresnel", 3)) // Conductor: type, x, y
5284 {
5285 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5286 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5287
5288 if (aFresnelType == "conductor")
5289 {
5290 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConductor (
5291 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())),
5292 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 2).c_str())));
5293 }
5294 else
5295 {
5296 std::cout << aFresnelErrorMessage;
5297 }
5298 }
5299 else if (aCmd.HasOption ("fresnel", 2)) // Dielectric, Constant: type, x
5300 {
5301 std::string aFresnelType = aCmd.Arg ("fresnel", 0);
5302 std::transform (aFresnelType.begin(), aFresnelType.end(), aFresnelType.begin(), ::tolower);
5303
5304 if (aFresnelType == "dielectric")
5305 {
5306 aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (
5307 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5308 }
5309 else if (aFresnelType == "constant")
5310 {
5311 aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (
5312 static_cast<Standard_ShortReal> (Draw::Atof (aCmd.Arg ("fresnel", 1).c_str())));
5313 }
5314 else
5315 {
5316 std::cout << aFresnelErrorMessage;
5317 }
5318 }
5319
5320 if (aCmd.HasOption ("normalize"))
5321 {
5322 aBSDF.Normalize();
5323 }
5324
5325 aMaterial.SetBSDF (aBSDF);
5326 anIObj->SetMaterial (aMaterial);
5327
5328 aView->Redraw();
5329
5330 return 0;
5331}
5332
f751596e 5333//==============================================================================
5334//function : VLoadSelection
5335//purpose : Adds given objects to map of AIS and loads selection primitives for them
5336//==============================================================================
5337static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
5338 Standard_Integer theArgNb,
5339 const char** theArgVec)
5340{
5341 if (theArgNb < 2)
5342 {
5343 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5344 return 1;
5345 }
5346
5347 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5348 if (aCtx.IsNull())
5349 {
5350 ViewerTest::ViewerInit();
5351 aCtx = ViewerTest::GetAISContext();
5352 }
5353
5354 // Parse input arguments
5355 TColStd_SequenceOfAsciiString aNamesOfIO;
5356 Standard_Boolean isLocal = Standard_False;
5357 for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
5358 {
5359 const TCollection_AsciiString aName = theArgVec[anArgIter];
5360 TCollection_AsciiString aNameCase = aName;
5361 aNameCase.LowerCase();
5362 if (aNameCase == "-local")
5363 {
5364 isLocal = Standard_True;
5365 }
5366 else
5367 {
5368 aNamesOfIO.Append (aName);
5369 }
5370 }
5371
5372 if (aNamesOfIO.IsEmpty())
5373 {
5374 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5375 return 1;
5376 }
5377
5378 // Prepare context
5379 if (isLocal && !aCtx->HasOpenedContext())
5380 {
5381 aCtx->OpenLocalContext (Standard_False);
5382 }
5383 else if (!isLocal && aCtx->HasOpenedContext())
5384 {
5385 aCtx->CloseAllContexts (Standard_False);
5386 }
5387
5388 // Load selection of interactive objects
5389 for (Standard_Integer anIter = 1; anIter <= aNamesOfIO.Length(); ++anIter)
5390 {
5391 const TCollection_AsciiString& aName = aNamesOfIO.Value (anIter);
5392
5b111128 5393 Handle(AIS_InteractiveObject) aShape;
5394 if (GetMapOfAIS().IsBound2 (aName))
5395 aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
5396 else
5397 aShape = GetAISShapeFromName (aName.ToCString());
f751596e 5398
5399 if (!aShape.IsNull())
5400 {
5401 if (!GetMapOfAIS().IsBound2 (aName))
5402 {
5403 GetMapOfAIS().Bind (aShape, aName);
5404 }
5405
5406 aCtx->Load (aShape, -1, Standard_False);
c3282ec1 5407 aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True);
f751596e 5408 }
5409 }
5410
5411 return 0;
5412}
5413
5414//==============================================================================
5415//function : VAutoActivateSelection
5416//purpose : Activates or deactivates auto computation of selection
5417//==============================================================================
5418static int VAutoActivateSelection (Draw_Interpretor& theDi,
5419 Standard_Integer theArgNb,
5420 const char** theArgVec)
5421{
5422
5423 if (theArgNb > 2)
5424 {
5425 std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
5426 return 1;
5427 }
5428
5429 Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
5430 if (aCtx.IsNull())
5431 {
5432 ViewerTest::ViewerInit();
5433 aCtx = ViewerTest::GetAISContext();
5434 }
5435
5436 if (theArgNb == 1)
5437 {
5438 TCollection_AsciiString aSelActivationString;
5439 if (aCtx->GetAutoActivateSelection())
5440 {
5441 aSelActivationString.Copy ("ON");
5442 }
5443 else
5444 {
5445 aSelActivationString.Copy ("OFF");
5446 }
5447
5448 theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
5449 }
5450 else
5451 {
5452 Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]);
5453 aCtx->SetAutoActivateSelection (toActivate);
5454 }
5455
5456 return 0;
5457}
5458
7fd59977 5459//==============================================================================
5460//function : ViewerTest::Commands
5461//purpose : Add all the viewer command in the Draw_Interpretor
5462//==============================================================================
5463
5464void ViewerTest::Commands(Draw_Interpretor& theCommands)
5465{
5466 ViewerTest::ViewerCommands(theCommands);
5467 ViewerTest::RelationCommands(theCommands);
5468 ViewerTest::ObjectCommands(theCommands);
5469 ViewerTest::FilletCommands(theCommands);
5470 ViewerTest::VoxelCommands(theCommands);
3946774d 5471 ViewerTest::OpenGlCommands(theCommands);
7fd59977 5472
5473 const char *group = "AIS_Display";
5474
5475 // display
1c88cbaf 5476 theCommands.Add("visos",
b6d587e3 5477 "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n"
5478 "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n",
5479 __FILE__, visos, group);
7fd59977 5480
5481 theCommands.Add("vdisplay",
faea8b40 5482 "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]"
5483 "\n\t\t: [-trsfPers {pan|zoom|rotate|trihedron|full|none}=none] [-trsfPersPos X Y [Z]] [-3d|-2d|-2dTopDown]"
af65fb19 5484 "\n\t\t: [-dispMode mode] [-highMode mode]"
faea8b40 5485 "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]"
5486 "\n\t\t: [-redisplay]"
af65fb19 5487 "\n\t\t: name1 [name2] ... [name n]"
519d35d8 5488 "\n\t\t: Displays named objects."
b6d587e3 5489 "\n\t\t: Option -local enables displaying of objects in local"
5490 "\n\t\t: selection context. Local selection context will be opened"
5491 "\n\t\t: if there is not any."
af65fb19 5492 "\n\t\t: -noupdate suppresses viewer redraw call."
5493 "\n\t\t: -mutable enables optimizations for mutable objects."
faea8b40 5494 "\n\t\t: -neutral draws objects in main viewer."
5495 "\n\t\t: -layer sets z-layer for objects. It can use -overlay|-underlay|-top|-topmost instead of -layer index for the default z-layers."
5496 "\n\t\t: -top draws objects on top of main presentations but below topmost."
5497 "\n\t\t: -topmost draws in overlay for 3D presentations with independent Depth."
5498 "\n\t\t: -overlay draws objects in overlay for 2D presentations (On-Screen-Display)."
5499 "\n\t\t: -underlay draws objects in underlay for 2D presentations (On-Screen-Display)."
af65fb19 5500 "\n\t\t: -selectable|-noselect controls selection of objects."
faea8b40 5501 "\n\t\t: -trsfPers sets a transform persistence flags. Flag 'full' is pan, zoom and rotate."
af65fb19 5502 "\n\t\t: -trsfPersPos sets an anchor point for transform persistence."
faea8b40 5503 "\n\t\t: -2d|-2dTopDown displays object in screen coordinates."
5504 "\n\t\t: -dispmode sets display mode for objects."
5505 "\n\t\t: -highmode sets hilight mode for objects."
5506 "\n\t\t: -redisplay recomputes presentation of objects.",
b6d587e3 5507 __FILE__, VDisplay2, group);
7fd59977 5508
f3889691 5509 theCommands.Add ("vupdate",
5510 "vupdate name1 [name2] ... [name n]"
5511 "\n\t\t: Updates named objects in interactive context",
5512 __FILE__, VUpdate, group);
5513
7fd59977 5514 theCommands.Add("verase",
b6d587e3 5515 "verase [-noupdate|-update] [-local] [name1] ... [name n]"
ac4aaa98 5516 "\n\t\t: Erases selected or named objects."
b6d587e3 5517 "\n\t\t: If there are no selected or named objects the whole viewer is erased."
5518 "\n\t\t: Option -local enables erasing of selected or named objects without"
5519 "\n\t\t: closing local selection context.",
5520 __FILE__, VErase, group);
7fd59977 5521
eef7fc64 5522 theCommands.Add("vremove",
b6d587e3 5523 "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
5524 "or vremove [-context] -all to remove all objects"
eef7fc64 5525 "\n\t\t: Removes selected or named objects."
5526 "\n\t\t If -context is in arguments, the objects are not deleted"
519d35d8 5527 "\n\t\t from the map of objects and names."
b6d587e3 5528 "\n\t\t: Option -local enables removing of selected or named objects without"
5529 "\n\t\t: closing local selection context. Empty local selection context will be"
5530 "\n\t\t: closed."
b7cd4ba7 5531 "\n\t\t: Option -noupdate suppresses viewer redraw call."
5532 "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
eef7fc64 5533 __FILE__, VRemove, group);
5534
7fd59977 5535 theCommands.Add("vdonly",
519d35d8 5536 "vdonly [-noupdate|-update] [name1] ... [name n]"
ac4aaa98 5537 "\n\t\t: Displays only selected or named objects",
7fd59977 5538 __FILE__,VDonly2,group);
5539
5540 theCommands.Add("vdisplayall",
b6d587e3 5541 "vidsplayall [-local]"
5542 "\n\t\t: Displays all erased interactive objects (see vdir and vstate)."
5543 "\n\t\t: Option -local enables displaying of the objects in local"
5544 "\n\t\t: selection context.",
5545 __FILE__, VDisplayAll, group);
7fd59977 5546
5547 theCommands.Add("veraseall",
b6d587e3 5548 "veraseall [-local]"
5549 "\n\t\t: Erases all objects displayed in the viewer."
5550 "\n\t\t: Option -local enables erasing of the objects in local"
5551 "\n\t\t: selection context.",
5552 __FILE__, VErase, group);
7fd59977 5553
5554 theCommands.Add("verasetype",
b6d587e3 5555 "verasetype <Type>"
ac4aaa98 5556 "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)",
b6d587e3 5557 __FILE__, VEraseType, group);
c2a388f8 5558 theCommands.Add("vbounding",
5559 "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]"
5560 "\n\t\t: [-print] [-hide]"
5561 "\n\t\t: Temporarily display bounding box of specified Interactive"
5562 "\n\t\t: Objects, or print it to console if -print is specified."
5563 "\n\t\t: Already displayed box might be hidden by -hide option.",
5564 __FILE__,VBounding,group);
5565
7fd59977 5566 theCommands.Add("vdisplaytype",
5567 "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ",
5568 __FILE__,VDisplayType,group);
5569
5570 theCommands.Add("vdisplaymode",
5571 "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ",
5572 __FILE__,VDispMode,group);
5573
5574 theCommands.Add("verasemode",
5575 "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects",
5576 __FILE__,VDispMode,group);
5577
5578 theCommands.Add("vsetdispmode",
ac4aaa98 5579 "vsetdispmode [name] mode(1,2,..)"
5580 "\n\t\t: Sets display mode for all, selected or named objects.",
7fd59977 5581 __FILE__,VDispMode,group);
5582
5583 theCommands.Add("vunsetdispmode",
ac4aaa98 5584 "vunsetdispmode [name]"
5585 "\n\t\t: Unsets custom display mode for selected or named objects.",
7fd59977 5586 __FILE__,VDispMode,group);
5587
5588 theCommands.Add("vdir",
ac4aaa98 5589 "Lists all objects displayed in 3D viewer",
519d35d8 5590 __FILE__,VDir,group);
7fd59977 5591
f978241f 5592#ifdef HAVE_FREEIMAGE
5593 #define DUMP_FORMATS "{png|bmp|jpg|gif}"
5594#else
5595 #define DUMP_FORMATS "{ppm}"
5596#endif
7fd59977 5597 theCommands.Add("vdump",
f978241f 5598 "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]"
5599 "\n\t\t: [-buffer rgb|rgba|depth=rgb]"
5600 "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]"
5601 "\n\t\t: Dumps content of the active view into image file",
7fd59977 5602 __FILE__,VDump,group);
5603
5604 theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects",
5605 __FILE__,VSubInt,group);
5606
ad3217cd 5607 theCommands.Add("vaspects",
6262338c 5608 "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]"
ac116c22 5609 "\n\t\t: [-setVisibility 0|1]"
5610 "\n\t\t: [-setColor ColorName] [-setcolor R G B] [-unsetColor]"
5611 "\n\t\t: [-setMaterial MatName] [-unsetMaterial]"
5612 "\n\t\t: [-setTransparency Transp] [-unsetTransparency]"
5613 "\n\t\t: [-setWidth LineWidth] [-unsetWidth]"
5614 "\n\t\t: [-setLineType {solid|dash|dot|dotDash}] [-unsetLineType]"
6262338c 5615 "\n\t\t: [-freeBoundary {off/on | 0/1}]"
5616 "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]"
5617 "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]"
ad3217cd 5618 "\n\t\t: [-subshapes subname1 [subname2 [...]]]"
5ad8c033 5619 "\n\t\t: [-isoontriangulation 0|1]"
5620 "\n\t\t: [-setMaxParamValue {value}]"
8a1170ad 5621 "\n\t\t: [-setSensitivity {selection_mode} {value}]"
ad3217cd 5622 "\n\t\t: Manage presentation properties of all, selected or named objects."
5623 "\n\t\t: When -subshapes is specified than following properties will be"
6262338c 5624 "\n\t\t: assigned to specified sub-shapes."
5625 "\n\t\t: When -defaults is specified than presentation properties will be"
5626 "\n\t\t: assigned to all objects that have not their own specified properties"
5627 "\n\t\t: and to all objects to be displayed in the future."
5628 "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.",
ad3217cd 5629 __FILE__,VAspects,group);
5630
7fd59977 5631 theCommands.Add("vsetcolor",
ad3217cd 5632 "vsetcolor [-noupdate|-update] [name] ColorName"
5633 "\n\t\t: Sets color for all, selected or named objects."
5634 "\n\t\t: Alias for vaspects -setcolor [name] ColorName.",
5635 __FILE__,VAspects,group);
7fd59977 5636
5637 theCommands.Add("vunsetcolor",
ad3217cd 5638 "vunsetcolor [-noupdate|-update] [name]"
5639 "\n\t\t: Resets color for all, selected or named objects."
5640 "\n\t\t: Alias for vaspects -unsetcolor [name].",
5641 __FILE__,VAspects,group);
7fd59977 5642
5643 theCommands.Add("vsettransparency",
ad3217cd 5644 "vsettransparency [-noupdate|-update] [name] Coefficient"
ac4aaa98 5645 "\n\t\t: Sets transparency for all, selected or named objects."
ad3217cd 5646 "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)."
5647 "\n\t\t: Alias for vaspects -settransp [name] Coefficient.",
5648 __FILE__,VAspects,group);
7fd59977 5649
5650 theCommands.Add("vunsettransparency",
ad3217cd 5651 "vunsettransparency [-noupdate|-update] [name]"
5652 "\n\t\t: Resets transparency for all, selected or named objects."
5653 "\n\t\t: Alias for vaspects -unsettransp [name].",
5654 __FILE__,VAspects,group);
7fd59977 5655
5656 theCommands.Add("vsetmaterial",
ad3217cd 5657 "vsetmaterial [-noupdate|-update] [name] MaterialName"
5658 "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.",
5659 __FILE__,VAspects,group);
7fd59977 5660
5661 theCommands.Add("vunsetmaterial",
ad3217cd 5662 "vunsetmaterial [-noupdate|-update] [name]"
5663 "\n\t\t: Alias for vaspects -unsetmaterial [name].",
5664 __FILE__,VAspects,group);
7fd59977 5665
5666 theCommands.Add("vsetwidth",
ad3217cd 5667 "vsetwidth [-noupdate|-update] [name] width(0->10)"
5668 "\n\t\t: Alias for vaspects -setwidth [name] width.",
5669 __FILE__,VAspects,group);
7fd59977 5670
5671 theCommands.Add("vunsetwidth",
ad3217cd 5672 "vunsetwidth [-noupdate|-update] [name]"
5673 "\n\t\t: Alias for vaspects -unsetwidth [name] width.",
5674 __FILE__,VAspects,group);
7fd59977 5675
99c56d44 5676 theCommands.Add("vsetinteriorstyle",
ad3217cd 5677 "vsetinteriorstyle [-noupdate|-update] [name] style"
5678 "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.",
5679 __FILE__,VSetInteriorStyle,group);
99c56d44 5680
7fd59977 5681 theCommands.Add("vsensdis",
faea8b40 5682 "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)."
5683 "\n\t\t: Standard entity types are those defined in Select3D package:"
5684 "\n\t\t: - sensitive box"
5685 "\n\t\t: - sensitive face"
5686 "\n\t\t: - sensitive curve"
5687 "\n\t\t: - sensitive segment"
5688 "\n\t\t: - sensitive circle"
5689 "\n\t\t: - sensitive point"
5690 "\n\t\t: - sensitive triangulation"
5691 "\n\t\t: - sensitive triangle"
5692 "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.",
5693 __FILE__,VDispSensi,group);
5694
7fd59977 5695 theCommands.Add("vsensera",
faea8b40 5696 "vsensera : erase active entities",
5697 __FILE__,VClearSensi,group);
7fd59977 5698
3c982548 5699 theCommands.Add("vselprecision",
28ee613b 5700 "vselprecision [-unset] [tolerance_value]"
5701 "\n\t\t Manages selection precision or prints current value if no parameter is passed."
5702 "\n\t\t -unset - restores default selection tolerance behavior, based on individual entity tolerance",
3c982548 5703 __FILE__,VSelPrecision,group);
5704
7fd59977 5705 theCommands.Add("vperf",
faea8b40 5706 "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
5707 "\n\t\t: Tests the animation of an object along a predefined trajectory.",
5708 __FILE__,VPerf,group);
7fd59977 5709
5710 theCommands.Add("vanimation",
5711 "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile",
5712 __FILE__,VAnimation,group);
5713
5714 theCommands.Add("vsetshading",
faea8b40 5715 "vsetshading : vsetshading name Quality(default=0.0008) "
5716