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