0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / ViewerTest / ViewerTest_FilletCommands.cxx
CommitLineData
b311480e 1// Created on: 1998-11-20
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17#include <ViewerTest.hxx>
7fd59977 18#include <BRepTest.hxx>
19#include <TColgp_Array1OfPnt2d.hxx>
20#include <DBRep.hxx>
21#include <Draw_Interpretor.hxx>
22#include <Draw_Appli.hxx>
23#include <BRepFilletAPI_MakeFillet.hxx>
7fd59977 24#include <BiTgte_Blend.hxx>
7fd59977 25#include <TopTools_ListIteratorOfListOfShape.hxx>
26#include <TopAbs_ShapeEnum.hxx>
27#include <TopoDS_Shape.hxx>
28#include <TopoDS_Compound.hxx>
29#include <TopoDS_Edge.hxx>
30#include <TopoDS_Vertex.hxx>
31#include <TopoDS.hxx>
32#include <TopExp.hxx>
33#include <TopExp_Explorer.hxx>
34
35#include <FilletSurf_Builder.hxx>
36#include <ChFi3d_FilletShape.hxx>
37#include <Geom_TrimmedCurve.hxx>
38#include <TopTools_ListOfShape.hxx>
39#include <FilletSurf_StatusType.hxx>
40#include <FilletSurf_ErrorTypeStatus.hxx>
41#include <TopAbs.hxx>
42#include <DrawTrSurf.hxx>
43#include <TopTools_HArray1OfShape.hxx>
44
45#include <AIS_InteractiveContext.hxx>
46#include <AIS_InteractiveObject.hxx>
47#include <AIS_Shape.hxx>
48
03155c18 49#ifdef _WIN32
7fd59977 50//#define strcasecmp strcmp Already defined in Standard
03155c18 51# include <stdio.h>
7fd59977 52#endif
53
7fd59977 54static Standard_Real t3d = 1.e-4;
55static Standard_Real t2d = 1.e-5;
56static Standard_Real ta = 1.e-2;
57static Standard_Real fl = 1.e-3;
58static Standard_Real tapp_angle = 1.e-2;
59static GeomAbs_Shape blend_cont = GeomAbs_C1;
60
61static BRepFilletAPI_MakeFillet* Rakk = 0;
7fd59977 62
63
64static void printtolblend(Draw_Interpretor& di)
65{
66 di<<"tolerance ang : "<<ta<<"\n";
67 di<<"tolerance 3d : "<<t3d<<"\n";
68 di<<"tolerance 2d : "<<t2d<<"\n";
69 di<<"fleche : "<<fl<<"\n";
70
71 di<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<"\n";
72}
73
7fd59977 74static Standard_Integer VBLEND(Draw_Interpretor& di, Standard_Integer narg, const char** a)
75{
76 if(Rakk != 0) {delete Rakk; Rakk = 0;}
77 printtolblend(di);
78 if (narg<5) return 1;
79
80 Standard_Integer NbToPick = (narg -4)/2;
7fd59977 81 Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
82 if(ViewerTest::PickShapes(TopAbs_EDGE,arr)){
83 for(Standard_Integer i=1;i<=NbToPick;i++){
84 TopoDS_Shape PickSh = arr->Value(i);
85 if(!PickSh.IsNull()){
86 DBRep::Set(a[(2*i+2)],PickSh);
87 }
88 }
89 }
90
91 TopoDS_Shape V = DBRep::Get(a[2]);
92 if(V.IsNull()) return 1;
93 ChFi3d_FilletShape FSh = ChFi3d_Rational;
94 if (narg%2 == 0) {
95 if (!strcasecmp(a[narg-1], "Q")) {
96 FSh = ChFi3d_QuasiAngular;
97 }
98 else if (!strcasecmp(a[narg-1], "P")) {
99 FSh = ChFi3d_Polynomial;
100 }
101 }
102 Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
103 Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
104 Rakk->SetContinuity(blend_cont, tapp_angle);
105 Standard_Real Rad;
106 TopoDS_Edge E;
107 Standard_Integer nbedge = 0;
108 for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
91322f44 109 Rad = Draw::Atof(a[2*ii + 1]);
7fd59977 110 TopoDS_Shape aLocalShape = DBRep::Get(a[(2*ii+2)],TopAbs_EDGE);
111 E = TopoDS::Edge(aLocalShape);
112// E = TopoDS::Edge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE));
113 if(!E.IsNull()){
114 Rakk->Add(Rad,E);
115 nbedge++;
116 }
117 }
118 if(!nbedge) return 1;
119 Rakk->Build();
120 if(!Rakk->IsDone()) return 1;
121 TopoDS_Shape res = Rakk->Shape();
122 DBRep::Set(a[1],res);
123
7fd59977 124 // visu resultat...
1c8fc6be 125 ViewerTest::Display (a[2], Handle(AIS_InteractiveObject)(), false);
126 ViewerTest::Display (a[1], new AIS_Shape (res), true);
7fd59977 127 return 0;
128}
129
130
131
132
133void ViewerTest::FilletCommands(Draw_Interpretor& theCommands)
134{
135 const char* g = "Viewer Fillet construction commands";
136 theCommands.Add("vblend",
137 "vblend result object rad1 ed1 rad2 ed2 ... [R/Q/P]",__FILE__,
138 VBLEND,g);
139}