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