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