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