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