1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_FinderShapeOn.cxx
21 // Created: Tue Jan 11 14:44:31 2005
22 // Author: Peter KURNEV
26 #include <GEOMAlgo_FinderShapeOn.ixx>
30 #include <TopAbs_ShapeEnum.hxx>
31 #include <TopAbs_Orientation.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Compound.hxx>
37 #include <TopoDS_Shell.hxx>
38 #include <TopoDS_Solid.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Iterator.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <TopTools_DataMapOfShapeShape.hxx>
47 #include <BRep_Builder.hxx>
48 #include <BRep_Tool.hxx>
51 #include <TopExp_Explorer.hxx>
53 #include <BRepLib_MakeFace.hxx>
54 #include <BRepLib_FaceError.hxx>
56 #include <BOPTools_DSFiller.hxx>
58 #include <GEOMAlgo_WireSolid.hxx>
59 #include <GEOMAlgo_ShellSolid.hxx>
60 #include <GEOMAlgo_VertexSolid.hxx>
61 #include <GEOMAlgo_ShapeSolid.hxx>
62 #include <GEOMAlgo_SolidSolid.hxx>
63 #include <GEOMAlgo_SurfaceTools.hxx>
64 #include <GEOMAlgo_Tools.hxx>
66 //=======================================================================
67 //function : GEOMAlgo_FinderShapeOn
69 //=======================================================================
70 GEOMAlgo_FinderShapeOn::GEOMAlgo_FinderShapeOn()
75 myShapeType=TopAbs_VERTEX;
76 myState=GEOMAlgo_ST_UNKNOWN;
77 myIsAnalytic=Standard_True;
79 //=======================================================================
82 //=======================================================================
83 GEOMAlgo_FinderShapeOn::~GEOMAlgo_FinderShapeOn()
86 //=======================================================================
87 //function : SetSurface
89 //=======================================================================
90 void GEOMAlgo_FinderShapeOn::SetSurface(const Handle(Geom_Surface)& aS)
94 //=======================================================================
97 //=======================================================================
98 const Handle(Geom_Surface)& GEOMAlgo_FinderShapeOn::Surface() const
102 //=======================================================================
103 //function : SetShapeType
105 //=======================================================================
106 void GEOMAlgo_FinderShapeOn::SetShapeType(const TopAbs_ShapeEnum aType)
110 //=======================================================================
111 //function : ShapeType
113 //=======================================================================
114 TopAbs_ShapeEnum GEOMAlgo_FinderShapeOn::ShapeType()const
118 //=======================================================================
119 //function : SetState
121 //=======================================================================
122 void GEOMAlgo_FinderShapeOn::SetState(const GEOMAlgo_State aState)
126 //=======================================================================
129 //=======================================================================
130 GEOMAlgo_State GEOMAlgo_FinderShapeOn::State() const
134 //=======================================================================
137 //=======================================================================
138 const TopTools_ListOfShape& GEOMAlgo_FinderShapeOn::Shapes() const
140 Standard_Boolean bIsConformState;
141 Standard_Integer i, aNb;
143 TopTools_ListOfShape* pL;
145 pL=(TopTools_ListOfShape*) &myLS;
149 for (i=1; i<=aNb; ++i) {
150 const TopoDS_Shape& aS=myMSS.FindKey(i);
151 aSt=myMSS.FindFromIndex(i);
153 bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
154 if (bIsConformState) {
160 //=======================================================================
163 //=======================================================================
164 void GEOMAlgo_FinderShapeOn::Perform()
171 if (!myResult.IsNull()){
180 myIsAnalytic=GEOMAlgo_SurfaceTools::IsAnalytic(mySurface);
187 if (myIsAnalytic && myShapeType==TopAbs_VERTEX) {
198 if(myErrorStatus || myWarningStatus) {
203 //=======================================================================
204 //function : FindVertices
206 //=======================================================================
207 void GEOMAlgo_FinderShapeOn::FindVertices()
209 Standard_Integer i, aNb, iErr;
211 TopAbs_Orientation aOr;
213 TopTools_IndexedMapOfShape aM;
215 TopExp::MapShapes(myArg1, TopAbs_FACE, aM);
216 const TopoDS_Face& aF=TopoDS::Face(aM(1));
217 aOr=aF.Orientation();
220 TopExp::MapShapes(myShape, myShapeType, aM);
223 myWarningStatus=10; // No found subshapes of type myShapeType
227 for (i=1; i<=aNb; ++i) {
228 const TopoDS_Shape& aS=aM(i);
229 const TopoDS_Vertex& aV=TopoDS::Vertex(aS);
230 aP=BRep_Tool::Pnt(aV);
231 iErr=GEOMAlgo_SurfaceTools::GetState(aP, mySurface, myTolerance, aSt);
232 if (aOr==TopAbs_REVERSED) {
233 aSt=GEOMAlgo_SurfaceTools::ReverseState(aSt);
238 //=======================================================================
241 //=======================================================================
242 void GEOMAlgo_FinderShapeOn::Find()
244 Standard_Integer i, aNb;
245 Standard_Boolean bICS;
246 TopTools_IndexedMapOfShape aM;
248 TopExp::MapShapes(myArg2, myShapeType, aM);
252 myWarningStatus=10; // No found subshapes of type myShapeType
256 bICS=GEOMAlgo_Tools::IsCompositeShape(myArg2);
257 if (!bICS || myIsAnalytic) {
258 TopoDS_Compound aCmp;
261 aBB.MakeCompound(aCmp);
262 for (i=1; i<=aNb; ++i) {
263 const TopoDS_Shape& aSi=aM(i);
272 for (i=1; i<=aNb; ++i) {
273 const TopoDS_Shape& aS=aM(i);
280 //=======================================================================
283 //=======================================================================
284 void GEOMAlgo_FinderShapeOn::Find(const TopoDS_Shape& aS)
288 Standard_Boolean bIsDone;
289 Standard_Integer i, iErr;
290 TopAbs_State aSts[]={TopAbs_IN, TopAbs_OUT, TopAbs_ON};
291 TopTools_ListIteratorOfListOfShape aIt;
292 BOPTools_DSFiller aDF;
294 // 1. Prepare DSFiller
295 aDF.SetShapes (myArg1, aS);
296 bIsDone=aDF.IsDone();
298 myErrorStatus=30; // wrong args are used for DSFiller
302 bIsDone=aDF.IsDone();
304 myErrorStatus=31; // DSFiller failed
309 GEOMAlgo_ShapeSolid* pSS;
310 GEOMAlgo_VertexSolid aVXS;
311 GEOMAlgo_WireSolid aWRS;
312 GEOMAlgo_ShellSolid aSHS;
313 GEOMAlgo_SolidSolid aSLS;
317 switch (myShapeType) {
328 aSLS.SetShape2(myArg2);
332 myErrorStatus=12; // unallowed subshape type
338 iErr=pSS->ErrorStatus();
340 myErrorStatus=32; // builder ShapeSolid failed
344 for (i=0; i<3; ++i) {
345 const TopTools_ListOfShape& aLS=pSS->Shapes(aSts[i]);
347 for (; aIt.More(); aIt.Next()) {
348 const TopoDS_Shape& aSImage=aIt.Value();
349 if (myImages.IsBound(aSImage)) {
350 const TopoDS_Shape& aSx=myImages.Find(aSImage);
351 myMSS.Add(aSx, aSts[i]);
354 myErrorStatus=33;// can not find original shape
360 //=======================================================================
361 //function : MakeArgument1
363 //=======================================================================
364 void GEOMAlgo_FinderShapeOn::MakeArgument1()
368 Standard_Integer i, aNb;
369 TopAbs_ShapeEnum aType;
370 BRepLib_FaceError aFErr;
371 BRepLib_MakeFace aMF;
372 TopTools_IndexedMapOfShape aM;
380 aMF.Init(mySurface, Standard_True);
382 if (aFErr!=BRepLib_FaceDone) {
383 myErrorStatus=20; // can not build the face
387 const TopoDS_Shape& aF=aMF.Shape();
388 aFace=TopoDS::Face(aF);
392 TopExp::MapShapes(aF, TopAbs_VERTEX, aM);
393 TopExp::MapShapes(aF, TopAbs_EDGE, aM);
395 for (i=1; i<=aNb; ++i) {
396 const TopoDS_Shape& aS=aM(i);
397 aType=aS.ShapeType();
399 case TopAbs_VERTEX: {
400 const TopoDS_Vertex& aVx=TopoDS::Vertex(aS);
401 aBB.UpdateVertex(aVx, myTolerance);
405 const TopoDS_Edge& aEx=TopoDS::Edge(aS);
406 aBB.UpdateEdge(aEx, myTolerance);
410 const TopoDS_Face& aFx=TopoDS::Face(aS);
411 aBB.UpdateFace(aFx, myTolerance);
420 aBB.MakeFace(aFace, mySurface, myTolerance);
430 //=======================================================================
431 //function : MakeArgument2
433 //=======================================================================
434 void GEOMAlgo_FinderShapeOn::MakeArgument2()
439 TopTools_DataMapOfShapeShape aOriginals;
443 GEOMAlgo_FinderShapeOn::CopySource(myShape, myImages, aOriginals, aSC);
447 //=======================================================================
448 //function : CheckData
450 //=======================================================================
451 void GEOMAlgo_FinderShapeOn::CheckData()
455 if(mySurface.IsNull()) {
456 myErrorStatus=10; // mySurface=NULL
460 if (myShape.IsNull()) {
461 myErrorStatus=11; // myShape=NULL
465 if (!(myShapeType==TopAbs_VERTEX ||
466 myShapeType==TopAbs_EDGE ||
467 myShapeType==TopAbs_FACE ||
468 myShapeType==TopAbs_SOLID)) {
469 myErrorStatus=12; // unallowed subshape type
473 if (myState==GEOMAlgo_ST_UNKNOWN ||
474 myState==GEOMAlgo_ST_INOUT) {
475 myErrorStatus=13; // unallowed state type
480 //=======================================================================
481 //function : CopySource
483 //=======================================================================
484 void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE,
485 TopTools_DataMapOfShapeShape& aImages,
486 TopTools_DataMapOfShapeShape& aOriginals,
489 Standard_Boolean bFree;
490 TopAbs_ShapeEnum aType;
495 aType=aE.ShapeType();
497 if (aOriginals.IsBound(aE)) {
498 aEx=aOriginals.ChangeFind(aE);
502 aEx=aE.EmptyCopied();
503 aOriginals.Bind(aE, aEx);
504 aImages.Bind(aEx, aE);
507 aR=(Standard_Integer)aType+1;
508 if (aR>TopAbs_VERTEX) {
513 aEx.Free(Standard_True);
515 aType=(TopAbs_ShapeEnum) aR;
517 aIt.Initialize(aE);//, Standard_False);
518 for (; aIt.More(); aIt.Next()) {
519 const TopoDS_Shape& aV=aIt.Value();
522 CopySource (aV, aImages, aOriginals, aVx);
524 aVx.Orientation(aV.Orientation());
534 // 10 -mySurface=NULL
536 // 12 -unallowed type of subshapes
537 // 13 -unallowed state
538 // 20 -can not build the face
539 // 30 -wrong args are used for DSFiller
540 // 31 -DSFiller failed
541 // 32 -builder ShapeSolid failed
542 // 33 -can not find original shape
546 // 10 -subshapes of type myShapeType can not be fond in myShape