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