1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 // 25.12.98 pdn renaming
15 // 02.02.99 cky/rln PRO17746: transmitting 'sketch' command to XSDRAWEUC
16 // 23.02.99 abv: method ShapeFix::FillFace() removed
17 // 02.03.99 cky/rln: command edgeregul only accepts tolerance
18 // 15.06.99 abv/pdn: command comptol added (from S4030)
20 #include <BRep_Builder.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepBuilderAPI.hxx>
23 #include <BRepClass3d_SolidClassifier.hxx>
24 #include <BRepLib.hxx>
25 #include <BRepTools_WireExplorer.hxx>
28 #include <DrawTrSurf.hxx>
29 #include <Geom2d_Curve.hxx>
30 #include <Geom_Curve.hxx>
31 #include <Geom_Surface.hxx>
32 #include <Geom_TrimmedCurve.hxx>
33 #include <GeomLib.hxx>
35 #include <gp_Pnt2d.hxx>
36 #include <Precision.hxx>
37 #include <SWDRAW_ShapeTool.hxx>
38 #include <TopAbs_ShapeEnum.hxx>
40 #include <TopExp_Explorer.hxx>
42 #include <TopoDS_Compound.hxx>
43 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Face.hxx>
45 #include <TopoDS_Iterator.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopoDS_Shell.hxx>
48 #include <TopoDS_Solid.hxx>
49 #include <TopoDS_Vertex.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <TopTools_IndexedMapOfShape.hxx>
57 static Standard_Integer XSHAPE_edge
58 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
60 if (argc < 2) { di<<"donner un nom de shape\n"; return 1 /* Error */; }
61 Standard_CString arg1 = argv[1];
62 TopoDS_Shape Shape = DBRep::Get(arg1);
63 if (Shape.IsNull()) { di<<arg1<<" inconnu\n"; return 1 /* Error */; }
64 Standard_Integer nbe = 0, nbf = 0; Standard_Real f3d,l3d;
66 for (TopExp_Explorer exp(Shape,TopAbs_EDGE); exp.More(); exp.Next()) {
67 TopoDS_Edge Edge = TopoDS::Edge (exp.Current()); nbe ++;
68 if (BRep_Tool::Degenerated(Edge)) continue;
69 Handle(Geom_Curve) curve3d = BRep_Tool::Curve (Edge,f3d,l3d);
70 if (curve3d.IsNull()) {
73 Sprintf (nomsh,"faultedge_%d",nbf);
74 di<<"Edge sans Curve3d, n0 "<<nbe<<"\n";
75 DBRep::Set (nomsh,Edge);
83 static Standard_Integer XSHAPE_explorewire
84 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
87 if (argc < 2) { di<<"donner un nom de wire\n"; return 1 /* Error */; }
88 Standard_CString arg1 = argv[1];
89 TopoDS_Shape Shape = DBRep::Get(arg1);
90 if (Shape.IsNull()) { di<<arg1<<" inconnu\n"; return 1 /* Error */; }
91 if (Shape.ShapeType() != TopAbs_WIRE) { di<<"Pas un WIRE\n"; return 1 /* Error */; }
92 TopoDS_Wire W = TopoDS::Wire (Shape);
95 Standard_CString arg2 = argv[2];
96 TopoDS_Shape aLocalShape = DBRep::Get(arg2);
97 F = TopoDS::Face ( aLocalShape );
100 Standard_Integer i,num = 0, nbw, nbe = 0;
101 TopTools_IndexedMapOfShape map;
102 for (TopoDS_Iterator ext(W); ext.More(); ext.Next()) {
103 if (ext.Value().ShapeType() != TopAbs_EDGE) continue;
104 TopoDS_Edge E = TopoDS::Edge (ext.Value());
105 nbe ++; num = map.Add(E);
107 int* nbs = new int[nbe+1]; for (i = 0; i <= nbe; i ++) nbs[i] = 0;
109 di<<"TopoDS_Iterator(EDGE) donne "<<nbe<<" Edges dont "<<num<<" distinctes\n";
112 for (TopExp_Explorer exe(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE); exe.More(); exe.Next()) nbw ++;
113 di<<"TopExp_Explorer(EDGE) donne "<<nbw<<" Edges\n";
115 BRepTools_WireExplorer bwe;
116 if (F.IsNull()) bwe.Init(W);
118 for (; bwe.More(); bwe.Next()) {
119 TopoDS_Edge E = TopoDS::Edge (bwe.Current());
121 num = map.FindIndex(E);
124 di<<"BRepTools_WireExplorer donne "<<nbw<<" Edges\n";
125 di<<"Par rapport a la map, edges sautees par WE en NOWE_num, passees > 1 fois en MULTWE_num\n";
126 if (nbs[0] > 0) di<<"NB : Edge n0 0 comptee "<<nbs[0]<<" fois\n";
127 for (i = 1; i <= nbe; i ++) {
129 di<<"Edge n0 "<<i<<" pas vue par WE\n";
130 Sprintf (nomsh,"NOWE_%d",i);
131 DBRep::Set (nomsh,map.FindKey(i));
132 } else if (nbs[i] > 1) {
133 di<<"Edge n0 "<<i<<" vue par WE : "<<nbs[i]<<" fois\n";
134 Sprintf (nomsh,"MULT_%d",i);
135 DBRep::Set (nomsh,map.FindKey(i));
144 static Standard_Integer XSHAPE_ssolid
145 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
147 if (argc < 3) { di<<"Give new solid name + shell name\n"; return 1 /* Error */; }
148 Standard_CString arg1 = argv[1];
149 TopoDS_Shape Shape = DBRep::Get(arg1);
150 if (Shape.IsNull()) { di<<"Shape unknown : "<<arg1<<"\n"; return 1 /* Error */; }
151 TopAbs_ShapeEnum shen = Shape.ShapeType();
152 if (shen == TopAbs_SOLID) {
153 di<<" Already a Solide ! nothing done\n";
156 if (shen != TopAbs_SHELL) {
157 di<<" Not a Shell\n"; return 1 /* Error */;
159 if (!Shape.Free ()) {
160 di<<"Shape non Free -> Freeing\n";
161 Shape.Free(Standard_True);
163 TopoDS_Shell sh = TopoDS::Shell (Shape);
168 // Pas encore fini : il faut une bonne orientation
169 BRepClass3d_SolidClassifier bsc3d (solid);
170 bsc3d.PerformInfinitePoint(BRepBuilderAPI::Precision());
171 if (bsc3d.State() == TopAbs_IN) {
172 // Ensuite, inverser C-A-D REPRENDRE LES SHELLS
173 // (l inversion du solide n est pas bien prise en compte)
174 di<<"NB : Shell to be reversed\n";
176 B.MakeSolid (soli2); // on recommence
181 DBRep::Set(argv[2],solid);
185 static Standard_Integer samerange (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
188 TopoDS_Shape Shape = DBRep::Get(argv[1]);
189 if (Shape.IsNull()) { di<<"Shape unknown: "<<argv[2]<<"\n"; return 1; }
191 for ( TopExp_Explorer exp(Shape,TopAbs_EDGE); exp.More(); exp.Next() ) {
192 TopoDS_Edge edge = TopoDS::Edge ( exp.Current() );
193 BRepLib::SameRange ( edge, Precision::PConfusion() );
196 else if ( argc == 7 ) {
197 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(argv[2]);
198 if (C.IsNull()) { di<<"Curve unknown: "<<argv[2]<<"\n"; return 1; }
200 Standard_Real oldFirst = Draw::Atof(argv[3]);
201 Standard_Real oldLast = Draw::Atof(argv[4]);
202 Standard_Real current_first = Draw::Atof(argv[5]);
203 Standard_Real current_last = Draw::Atof(argv[6]);
204 Standard_Real Tol = Precision::PConfusion();
205 Handle(Geom2d_Curve) NewC2d;
206 GeomLib::SameRange(Tol, C, oldFirst,oldLast,
207 current_first, current_last, NewC2d);
208 DrawTrSurf::Set(argv[1],NewC2d);
211 di << "Apply BRepLib::SameRange() to shape or GeomLib::SameRange() to pcurve:\n";
212 di << "> samerange shape\n";
214 di << "> samerange newcurve curve2d first last newfirst newlast\n";
220 // ########################################
221 // ## DECLARATIONS ##
222 // ########################################
224 void SWDRAW_ShapeTool::InitCommands (Draw_Interpretor& theCommands)
226 static int initactor = 0;
236 theCommands.Add ("anaedges","nom shape",
237 __FILE__,XSHAPE_edge,g);
238 theCommands.Add ("expwire","nom wire [nom face]",
239 __FILE__,XSHAPE_explorewire,g);
241 theCommands.Add ("ssolid","nom shell + nouveau nom solid",
242 __FILE__,XSHAPE_ssolid,g);
244 theCommands.Add ("samerange","{ shape | result curve2d first last newfirst newlast }",
245 __FILE__,samerange,g);