b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | // 25.12.98 pdn renaming |
19 | // 02.02.99 cky/rln PRO17746: transmitting 'sketch' command to XSDRAWEUC |
20 | // 23.02.99 abv: method ShapeFix::FillFace() removed |
21 | // 02.03.99 cky/rln: command edgeregul only accepts tolerance |
22 | // 15.06.99 abv/pdn: command comptol added (from S4030) |
23 | #include <SWDRAW_ShapeTool.ixx> |
24 | |
91322f44 |
25 | #include <Draw.hxx> |
7fd59977 |
26 | #include <DBRep.hxx> |
27 | #include <TopAbs_ShapeEnum.hxx> |
28 | #include <TopoDS.hxx> |
29 | #include <TopoDS_Shape.hxx> |
30 | #include <TopoDS_Compound.hxx> |
31 | #include <TopoDS_Shell.hxx> |
32 | #include <TopoDS_Solid.hxx> |
33 | #include <TopoDS_Face.hxx> |
34 | #include <TopoDS_Wire.hxx> |
35 | #include <TopoDS_Edge.hxx> |
36 | #include <TopoDS_Vertex.hxx> |
37 | |
38 | #include <BRepBuilderAPI.hxx> |
39 | |
40 | // + edge, face |
41 | #include <TopoDS_Iterator.hxx> |
42 | #include <TopExp_Explorer.hxx> |
43 | #include <TopExp.hxx> |
44 | #include <BRep_Tool.hxx> |
45 | #include <Geom_Curve.hxx> |
46 | #include <Geom_Surface.hxx> |
47 | #include <gp_Pnt.hxx> |
48 | #include <gp_Pnt2d.hxx> |
49 | #include <TopTools_IndexedMapOfShape.hxx> |
50 | #include <BRepClass3d_SolidClassifier.hxx> |
51 | |
52 | #include <BRepTools_WireExplorer.hxx> |
53 | #include <TopoDS_Iterator.hxx> |
54 | |
55 | #include <BRep_Builder.hxx> |
56 | |
57 | |
58 | |
59 | // + edgeregul/updtol |
60 | #include <BRepLib.hxx> |
61 | |
62 | // + fillface |
63 | #include <Geom_TrimmedCurve.hxx> |
64 | #include <stdio.h> |
65 | #include <Precision.hxx> |
66 | #include <DrawTrSurf.hxx> |
67 | #include <GeomLib.hxx> |
68 | |
69 | |
70 | static Standard_Integer XSHAPE_edge |
71 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
72 | { |
73 | if (argc < 2) { di<<"donner un nom de shape"<<"\n"; return 1 /* Error */; } |
74 | Standard_CString arg1 = argv[1]; |
75 | TopoDS_Shape Shape = DBRep::Get(arg1); |
76 | if (Shape.IsNull()) { di<<arg1<<" inconnu"<<"\n"; return 1 /* Error */; } |
77 | Standard_Integer nbe = 0, nbf = 0; Standard_Real f3d,l3d; |
78 | |
79 | for (TopExp_Explorer exp(Shape,TopAbs_EDGE); exp.More(); exp.Next()) { |
80 | TopoDS_Edge Edge = TopoDS::Edge (exp.Current()); nbe ++; |
81 | if (BRep_Tool::Degenerated(Edge)) continue; |
82 | Handle(Geom_Curve) curve3d = BRep_Tool::Curve (Edge,f3d,l3d); |
83 | if (curve3d.IsNull()) { |
84 | char nomsh[30]; |
85 | nbf ++; |
91322f44 |
86 | Sprintf (nomsh,"faultedge_%d",nbf); |
7fd59977 |
87 | di<<"Edge sans Curve3d, n0 "<<nbe<<"\n"; |
88 | DBRep::Set (nomsh,Edge); |
89 | } |
90 | } |
91 | return 0; |
92 | } |
93 | |
94 | |
95 | |
96 | static Standard_Integer XSHAPE_explorewire |
97 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
98 | { |
99 | char nomsh[30]; |
100 | if (argc < 2) { di<<"donner un nom de wire"<<"\n"; return 1 /* Error */; } |
101 | Standard_CString arg1 = argv[1]; |
102 | TopoDS_Shape Shape = DBRep::Get(arg1); |
103 | if (Shape.IsNull()) { di<<arg1<<" inconnu"<<"\n"; return 1 /* Error */; } |
104 | if (Shape.ShapeType() != TopAbs_WIRE) { di<<"Pas un WIRE"<<"\n"; return 1 /* Error */; } |
105 | TopoDS_Wire W = TopoDS::Wire (Shape); |
106 | TopoDS_Face F; |
107 | if (argc > 2) { |
108 | Standard_CString arg2 = argv[2]; |
109 | TopoDS_Shape aLocalShape = DBRep::Get(arg2); |
110 | F = TopoDS::Face ( aLocalShape ); |
111 | } |
112 | |
113 | Standard_Integer i,num = 0, nbw, nbe = 0; |
114 | TopTools_IndexedMapOfShape map; |
115 | for (TopoDS_Iterator ext(W); ext.More(); ext.Next()) { |
116 | if (ext.Value().ShapeType() != TopAbs_EDGE) continue; |
117 | TopoDS_Edge E = TopoDS::Edge (ext.Value()); |
118 | nbe ++; num = map.Add(E); |
119 | } |
120 | int* nbs = new int[nbe+1]; for (i = 0; i <= nbe; i ++) nbs[i] = 0; |
121 | |
122 | di<<"TopoDS_Iterator(EDGE) donne "<<nbe<<" Edges dont "<<num<<" distinctes"<<"\n"; |
123 | nbe = num; |
124 | nbw = 0; |
125 | for (TopExp_Explorer exe(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE); exe.More(); exe.Next()) nbw ++; |
126 | di<<"TopExp_Explorer(EDGE) donne "<<nbw<<" Edges"<<"\n"; |
127 | nbw = 0; |
128 | BRepTools_WireExplorer bwe; |
129 | if (F.IsNull()) bwe.Init(W); |
130 | else bwe.Init (W,F); |
131 | for (; bwe.More(); bwe.Next()) { |
132 | TopoDS_Edge E = TopoDS::Edge (bwe.Current()); |
133 | nbw ++; |
134 | num = map.FindIndex(E); |
135 | nbs[num] ++; |
136 | } |
137 | di<<"BRepTools_WireExplorer donne "<<nbw<<" Edges"<<"\n"; |
138 | di<<"Par rapport a la map, edges sautees par WE en NOWE_num, passees > 1 fois en MULTWE_num"<<"\n"; |
139 | if (nbs[0] > 0) di<<"NB : Edge n0 0 comptee "<<nbs[0]<<" fois"<<"\n"; |
140 | for (i = 1; i <= nbe; i ++) { |
141 | if (nbs[i] < 1) { |
142 | di<<"Edge n0 "<<i<<" pas vue par WE"<<"\n"; |
91322f44 |
143 | Sprintf (nomsh,"NOWE_%d",i); |
7fd59977 |
144 | DBRep::Set (nomsh,map.FindKey(i)); |
145 | } else if (nbs[i] > 1) { |
146 | di<<"Edge n0 "<<i<<" vue par WE : "<<nbs[i]<<" fois"<<"\n"; |
91322f44 |
147 | Sprintf (nomsh,"MULT_%d",i); |
7fd59977 |
148 | DBRep::Set (nomsh,map.FindKey(i)); |
149 | } |
150 | } |
151 | delete [] nbs; |
152 | return 0; |
153 | } |
154 | |
155 | |
156 | |
157 | static Standard_Integer XSHAPE_ssolid |
158 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
159 | { |
160 | if (argc < 3) { di<<"Give new solid name + shell name"<<"\n"; return 1 /* Error */; } |
161 | Standard_CString arg1 = argv[1]; |
162 | TopoDS_Shape Shape = DBRep::Get(arg1); |
163 | if (Shape.IsNull()) { di<<"Shape unknown : "<<arg1<<"\n"; return 1 /* Error */; } |
164 | TopAbs_ShapeEnum shen = Shape.ShapeType(); |
165 | if (shen == TopAbs_SOLID) { |
166 | di<<" Already a Solide ! nothing done"<<"\n"; |
167 | return 0; |
168 | } |
169 | if (shen != TopAbs_SHELL) { |
170 | di<<" Not a Shell"<<"\n"; return 1 /* Error */; |
171 | } |
172 | if (!Shape.Free ()) { |
173 | di<<"Shape non Free -> Freeing"<<"\n"; |
174 | Shape.Free(Standard_True); |
175 | } |
176 | TopoDS_Shell sh = TopoDS::Shell (Shape); |
177 | TopoDS_Solid solid; |
178 | BRep_Builder B; |
179 | B.MakeSolid (solid); |
180 | B.Add (solid,sh); |
181 | // Pas encore fini : il faut une bonne orientation |
182 | BRepClass3d_SolidClassifier bsc3d (solid); |
183 | bsc3d.PerformInfinitePoint(BRepBuilderAPI::Precision()); |
184 | if (bsc3d.State() == TopAbs_IN) { |
185 | // Ensuite, inverser C-A-D REPRENDRE LES SHELLS |
186 | // (l inversion du solide n est pas bien prise en compte) |
187 | di<<"NB : Shell to be reversed"<<"\n"; |
188 | TopoDS_Solid soli2; |
189 | B.MakeSolid (soli2); // on recommence |
190 | sh.Reverse(); |
191 | B.Add (soli2,sh); |
192 | solid = soli2; |
193 | } |
194 | DBRep::Set(argv[2],solid); |
195 | return 0; // Done |
196 | } |
197 | |
198 | |
199 | static Standard_Integer XSHAPE_edgeregul |
200 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
201 | { |
202 | //cky/rln 03.02.99 To eliminate dependence of SWDRAW on TKXSBase (to use only ShapeHealing) |
1d47d8d0 |
203 | Standard_Real tolang = Precision::Angular(); // = Interface_Static::RVal("XSTEP.encoderegularity.angle"); |
7fd59977 |
204 | // if (argc < 3) di<<"Current value for regularity angle : "<<tolang<<"\n"; |
205 | if (argc < 3) { |
206 | di<<"Donner nom de shape.\n + option : angle en radian, sinon la valeur courante est prise"<<"\n"; |
207 | return 0; |
208 | } |
209 | Standard_CString arg1 = argv[1]; |
210 | Standard_CString arg2 = argv[2]; |
91322f44 |
211 | if (argc > 2) tolang = Draw::Atof (arg2); |
7fd59977 |
212 | if (tolang <= 0) { |
213 | di<<"Not a suitable value : "<<tolang<<"\n"; |
214 | return 1 /* Error */; |
215 | } |
216 | TopoDS_Shape Shape = DBRep::Get(arg1); |
217 | if (Shape.IsNull()) { di<<"Shape unknown : "<<arg1<<"\n"; return 1 /* Error */; } |
218 | |
219 | BRepLib::EncodeRegularity (Shape,tolang); |
220 | return 0; // Done |
221 | } |
222 | |
223 | static Standard_Integer samerange (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
224 | { |
225 | if ( argc ==2 ) { |
226 | TopoDS_Shape Shape = DBRep::Get(argv[1]); |
227 | if (Shape.IsNull()) { di<<"Shape unknown: "<<argv[2]<<"\n"; return 1; } |
228 | |
229 | for ( TopExp_Explorer exp(Shape,TopAbs_EDGE); exp.More(); exp.Next() ) { |
230 | TopoDS_Edge edge = TopoDS::Edge ( exp.Current() ); |
231 | BRepLib::SameRange ( edge, Precision::PConfusion() ); |
232 | } |
233 | } |
234 | else if ( argc == 7 ) { |
235 | Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(argv[2]); |
236 | if (C.IsNull()) { di<<"Curve unknown: "<<argv[2]<<"\n"; return 1; } |
237 | |
91322f44 |
238 | Standard_Real oldFirst = Draw::Atof(argv[3]); |
239 | Standard_Real oldLast = Draw::Atof(argv[4]); |
240 | Standard_Real current_first = Draw::Atof(argv[5]); |
241 | Standard_Real current_last = Draw::Atof(argv[6]); |
7fd59977 |
242 | Standard_Real Tol = Precision::PConfusion(); |
243 | Handle(Geom2d_Curve) NewC2d; |
244 | GeomLib::SameRange(Tol, C, oldFirst,oldLast, |
245 | current_first, current_last, NewC2d); |
246 | DrawTrSurf::Set(argv[1],NewC2d); |
247 | } |
248 | else { |
249 | di << "Apply BRepLib::SameRange() to shape or GeomLib::SameRange() to pcurve:" << "\n"; |
250 | di << "> samerange shape" << "\n"; |
251 | di << "or" << "\n"; |
252 | di << "> samerange newcurve curve2d first last newfirst newlast" << "\n"; |
253 | } |
254 | |
255 | return 0; |
256 | } |
257 | |
258 | // ######################################## |
259 | // ## DECLARATIONS ## |
260 | // ######################################## |
261 | |
262 | static int initactor = 0; |
263 | |
264 | void SWDRAW_ShapeTool::InitCommands (Draw_Interpretor& theCommands) |
265 | { |
266 | if (initactor) return; initactor = 1; |
267 | |
268 | const char* g; |
269 | g = "DE: old"; |
270 | |
271 | theCommands.Add ("anaedges","nom shape", |
272 | __FILE__,XSHAPE_edge,g); |
273 | theCommands.Add ("expwire","nom wire [nom face]", |
274 | __FILE__,XSHAPE_explorewire,g); |
275 | |
276 | theCommands.Add ("ssolid","nom shell + nouveau nom solid", |
277 | __FILE__,XSHAPE_ssolid,g); |
278 | |
279 | theCommands.Add ("edgeregul","shape val", |
280 | __FILE__,XSHAPE_edgeregul,g); |
281 | |
282 | theCommands.Add ("samerange","{ shape | result curve2d first last newfirst newlast }", |
283 | __FILE__,samerange,g); |
284 | } |