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