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