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