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