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