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