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