0028643: Coding rules - eliminate GCC compiler warnings -Wmisleading-indentation
[occt.git] / src / SWDRAW / SWDRAW_ShapeTool.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 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)
7fd59977 19
42cf5bc1 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>
7fd59977 26#include <DBRep.hxx>
42cf5bc1 27#include <Draw.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>
34#include <gp_Pnt.hxx>
35#include <gp_Pnt2d.hxx>
36#include <Precision.hxx>
37#include <SWDRAW_ShapeTool.hxx>
7fd59977 38#include <TopAbs_ShapeEnum.hxx>
42cf5bc1 39#include <TopExp.hxx>
40#include <TopExp_Explorer.hxx>
7fd59977 41#include <TopoDS.hxx>
7fd59977 42#include <TopoDS_Compound.hxx>
42cf5bc1 43#include <TopoDS_Edge.hxx>
44#include <TopoDS_Face.hxx>
45#include <TopoDS_Iterator.hxx>
46#include <TopoDS_Shape.hxx>
7fd59977 47#include <TopoDS_Shell.hxx>
48#include <TopoDS_Solid.hxx>
7fd59977 49#include <TopoDS_Vertex.hxx>
42cf5bc1 50#include <TopoDS_Wire.hxx>
7fd59977 51#include <TopTools_IndexedMapOfShape.hxx>
7fd59977 52
42cf5bc1 53#include <stdio.h>
54// + edge, face
7fd59977 55// + edgeregul/updtol
7fd59977 56// + fillface
7fd59977 57static Standard_Integer XSHAPE_edge
58 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
59{
586db386 60 if (argc < 2) { di<<"donner un nom de shape\n"; return 1 /* Error */; }
7fd59977 61 Standard_CString arg1 = argv[1];
62 TopoDS_Shape Shape = DBRep::Get(arg1);
586db386 63 if (Shape.IsNull()) { di<<arg1<<" inconnu\n"; return 1 /* Error */; }
7fd59977 64 Standard_Integer nbe = 0, nbf = 0; Standard_Real f3d,l3d;
65
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()) {
71 char nomsh[30];
72 nbf ++;
91322f44 73 Sprintf (nomsh,"faultedge_%d",nbf);
7fd59977 74 di<<"Edge sans Curve3d, n0 "<<nbe<<"\n";
75 DBRep::Set (nomsh,Edge);
76 }
77 }
78 return 0;
79}
80
81
82
83static Standard_Integer XSHAPE_explorewire
84 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
85{
86 char nomsh[30];
586db386 87 if (argc < 2) { di<<"donner un nom de wire\n"; return 1 /* Error */; }
7fd59977 88 Standard_CString arg1 = argv[1];
89 TopoDS_Shape Shape = DBRep::Get(arg1);
586db386 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 */; }
7fd59977 92 TopoDS_Wire W = TopoDS::Wire (Shape);
93 TopoDS_Face F;
94 if (argc > 2) {
95 Standard_CString arg2 = argv[2];
96 TopoDS_Shape aLocalShape = DBRep::Get(arg2);
97 F = TopoDS::Face ( aLocalShape );
98 }
99
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);
106 }
107 int* nbs = new int[nbe+1]; for (i = 0; i <= nbe; i ++) nbs[i] = 0;
108
586db386 109 di<<"TopoDS_Iterator(EDGE) donne "<<nbe<<" Edges dont "<<num<<" distinctes\n";
7fd59977 110 nbe = num;
111 nbw = 0;
112 for (TopExp_Explorer exe(W.Oriented(TopAbs_FORWARD),TopAbs_EDGE); exe.More(); exe.Next()) nbw ++;
586db386 113 di<<"TopExp_Explorer(EDGE) donne "<<nbw<<" Edges\n";
7fd59977 114 nbw = 0;
115 BRepTools_WireExplorer bwe;
116 if (F.IsNull()) bwe.Init(W);
117 else bwe.Init (W,F);
118 for (; bwe.More(); bwe.Next()) {
119 TopoDS_Edge E = TopoDS::Edge (bwe.Current());
120 nbw ++;
121 num = map.FindIndex(E);
122 nbs[num] ++;
123 }
586db386 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";
7fd59977 127 for (i = 1; i <= nbe; i ++) {
128 if (nbs[i] < 1) {
586db386 129 di<<"Edge n0 "<<i<<" pas vue par WE\n";
91322f44 130 Sprintf (nomsh,"NOWE_%d",i);
7fd59977 131 DBRep::Set (nomsh,map.FindKey(i));
132 } else if (nbs[i] > 1) {
586db386 133 di<<"Edge n0 "<<i<<" vue par WE : "<<nbs[i]<<" fois\n";
91322f44 134 Sprintf (nomsh,"MULT_%d",i);
7fd59977 135 DBRep::Set (nomsh,map.FindKey(i));
136 }
137 }
138 delete [] nbs;
139 return 0;
140}
141
142
143
144static Standard_Integer XSHAPE_ssolid
145 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
146{
586db386 147 if (argc < 3) { di<<"Give new solid name + shell name\n"; return 1 /* Error */; }
7fd59977 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) {
586db386 153 di<<" Already a Solide ! nothing done\n";
7fd59977 154 return 0;
155 }
156 if (shen != TopAbs_SHELL) {
586db386 157 di<<" Not a Shell\n"; return 1 /* Error */;
7fd59977 158 }
159 if (!Shape.Free ()) {
586db386 160 di<<"Shape non Free -> Freeing\n";
7fd59977 161 Shape.Free(Standard_True);
162 }
163 TopoDS_Shell sh = TopoDS::Shell (Shape);
164 TopoDS_Solid solid;
165 BRep_Builder B;
166 B.MakeSolid (solid);
167 B.Add (solid,sh);
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)
586db386 174 di<<"NB : Shell to be reversed\n";
7fd59977 175 TopoDS_Solid soli2;
176 B.MakeSolid (soli2); // on recommence
177 sh.Reverse();
178 B.Add (soli2,sh);
179 solid = soli2;
180 }
181 DBRep::Set(argv[2],solid);
182 return 0; // Done
183}
184
7fd59977 185static Standard_Integer samerange (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
186{
187 if ( argc ==2 ) {
188 TopoDS_Shape Shape = DBRep::Get(argv[1]);
189 if (Shape.IsNull()) { di<<"Shape unknown: "<<argv[2]<<"\n"; return 1; }
190
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() );
194 }
195 }
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; }
199
91322f44 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]);
7fd59977 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);
209 }
210 else {
586db386 211 di << "Apply BRepLib::SameRange() to shape or GeomLib::SameRange() to pcurve:\n";
212 di << "> samerange shape\n";
213 di << "or\n";
214 di << "> samerange newcurve curve2d first last newfirst newlast\n";
7fd59977 215 }
216
217 return 0;
218}
219
220// ########################################
221// ## DECLARATIONS ##
222// ########################################
223
7fd59977 224void SWDRAW_ShapeTool::InitCommands (Draw_Interpretor& theCommands)
225{
c48e2889 226 static int initactor = 0;
227 if (initactor)
228 {
229 return;
230 }
231 initactor = 1;
7fd59977 232
233 const char* g;
234 g = "DE: old";
235
236 theCommands.Add ("anaedges","nom shape",
237 __FILE__,XSHAPE_edge,g);
238 theCommands.Add ("expwire","nom wire [nom face]",
239 __FILE__,XSHAPE_explorewire,g);
240
241 theCommands.Add ("ssolid","nom shell + nouveau nom solid",
242 __FILE__,XSHAPE_ssolid,g);
243
7fd59977 244 theCommands.Add ("samerange","{ shape | result curve2d first last newfirst newlast }",
245 __FILE__,samerange,g);
246}