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