1 // File: GEOMAlgo_FinderShapeOn.cxx
2 // Created: Tue Jan 11 14:44:31 2005
3 // Author: Peter KURNEV
7 #include <GEOMAlgo_FinderShapeOn.ixx>
11 #include <TopAbs_ShapeEnum.hxx>
12 #include <TopAbs_Orientation.hxx>
15 #include <TopoDS_Face.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <TopoDS_Compound.hxx>
18 #include <TopoDS_Shell.hxx>
19 #include <TopoDS_Solid.hxx>
20 #include <TopoDS_Vertex.hxx>
21 #include <TopoDS_Edge.hxx>
22 #include <TopoDS_Iterator.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
25 #include <TopTools_IndexedMapOfShape.hxx>
26 #include <TopTools_DataMapOfShapeShape.hxx>
28 #include <BRep_Builder.hxx>
29 #include <BRep_Tool.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <BRepLib_MakeFace.hxx>
35 #include <BRepLib_FaceError.hxx>
37 #include <BOPTools_DSFiller.hxx>
39 #include <GEOMAlgo_WireSolid.hxx>
40 #include <GEOMAlgo_ShellSolid.hxx>
41 #include <GEOMAlgo_VertexSolid.hxx>
42 #include <GEOMAlgo_ShapeSolid.hxx>
43 #include <GEOMAlgo_SolidSolid.hxx>
44 #include <GEOMAlgo_SurfaceTools.hxx>
45 #include <GEOMAlgo_Tools.hxx>
47 //=======================================================================
48 //function : GEOMAlgo_FinderShapeOn
50 //=======================================================================
51 GEOMAlgo_FinderShapeOn::GEOMAlgo_FinderShapeOn()
56 myShapeType=TopAbs_VERTEX;
57 myState=GEOMAlgo_ST_UNKNOWN;
58 myIsAnalytic=Standard_True;
60 //=======================================================================
63 //=======================================================================
64 GEOMAlgo_FinderShapeOn::~GEOMAlgo_FinderShapeOn()
67 //=======================================================================
68 //function : SetSurface
70 //=======================================================================
71 void GEOMAlgo_FinderShapeOn::SetSurface(const Handle(Geom_Surface)& aS)
75 //=======================================================================
78 //=======================================================================
79 const Handle(Geom_Surface)& GEOMAlgo_FinderShapeOn::Surface() const
83 //=======================================================================
84 //function : SetShapeType
86 //=======================================================================
87 void GEOMAlgo_FinderShapeOn::SetShapeType(const TopAbs_ShapeEnum aType)
91 //=======================================================================
92 //function : ShapeType
94 //=======================================================================
95 TopAbs_ShapeEnum GEOMAlgo_FinderShapeOn::ShapeType()const
99 //=======================================================================
100 //function : SetState
102 //=======================================================================
103 void GEOMAlgo_FinderShapeOn::SetState(const GEOMAlgo_State aState)
107 //=======================================================================
110 //=======================================================================
111 GEOMAlgo_State GEOMAlgo_FinderShapeOn::State() const
115 //=======================================================================
118 //=======================================================================
119 const TopTools_ListOfShape& GEOMAlgo_FinderShapeOn::Shapes() const
121 Standard_Boolean bIsConformState;
122 Standard_Integer i, aNb;
124 TopTools_ListOfShape* pL;
126 pL=(TopTools_ListOfShape*) &myLS;
130 for (i=1; i<=aNb; ++i) {
131 const TopoDS_Shape& aS=myMSS.FindKey(i);
132 aSt=myMSS.FindFromIndex(i);
134 bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
135 if (bIsConformState) {
141 //=======================================================================
144 //=======================================================================
145 void GEOMAlgo_FinderShapeOn::Perform()
152 if (!myResult.IsNull()){
161 myIsAnalytic=GEOMAlgo_SurfaceTools::IsAnalytic(mySurface);
168 if (myIsAnalytic && myShapeType==TopAbs_VERTEX) {
179 if(myErrorStatus || myWarningStatus) {
184 //=======================================================================
185 //function : FindVertices
187 //=======================================================================
188 void GEOMAlgo_FinderShapeOn::FindVertices()
190 Standard_Integer i, aNb, iErr;
192 TopAbs_Orientation aOr;
194 TopTools_IndexedMapOfShape aM;
196 TopExp::MapShapes(myArg1, TopAbs_FACE, aM);
197 const TopoDS_Face& aF=TopoDS::Face(aM(1));
198 aOr=aF.Orientation();
201 TopExp::MapShapes(myShape, myShapeType, aM);
204 myWarningStatus=10; // No found subshapes of type myShapeType
208 for (i=1; i<=aNb; ++i) {
209 const TopoDS_Shape& aS=aM(i);
210 const TopoDS_Vertex& aV=TopoDS::Vertex(aS);
211 aP=BRep_Tool::Pnt(aV);
212 iErr=GEOMAlgo_SurfaceTools::GetState(aP, mySurface, myTolerance, aSt);
213 if (aOr==TopAbs_REVERSED) {
214 aSt=GEOMAlgo_SurfaceTools::ReverseState(aSt);
219 //=======================================================================
222 //=======================================================================
223 void GEOMAlgo_FinderShapeOn::Find()
225 Standard_Integer i, aNb;
226 Standard_Boolean bICS;
227 TopTools_IndexedMapOfShape aM;
229 TopExp::MapShapes(myArg2, myShapeType, aM);
233 myWarningStatus=10; // No found subshapes of type myShapeType
237 bICS=GEOMAlgo_Tools::IsCompositeShape(myArg2);
238 if (!bICS || myIsAnalytic) {
239 TopoDS_Compound aCmp;
242 aBB.MakeCompound(aCmp);
243 for (i=1; i<=aNb; ++i) {
244 const TopoDS_Shape& aSi=aM(i);
253 for (i=1; i<=aNb; ++i) {
254 const TopoDS_Shape& aS=aM(i);
261 //=======================================================================
264 //=======================================================================
265 void GEOMAlgo_FinderShapeOn::Find(const TopoDS_Shape& aS)
269 Standard_Boolean bIsDone;
270 Standard_Integer i, iErr;
271 TopAbs_State aSts[]={TopAbs_IN, TopAbs_OUT, TopAbs_ON};
272 TopTools_ListIteratorOfListOfShape aIt;
273 BOPTools_DSFiller aDF;
275 // 1. Prepare DSFiller
276 aDF.SetShapes (myArg1, aS);
277 bIsDone=aDF.IsDone();
279 myErrorStatus=30; // wrong args are used for DSFiller
283 bIsDone=aDF.IsDone();
285 myErrorStatus=31; // DSFiller failed
290 GEOMAlgo_ShapeSolid* pSS;
291 GEOMAlgo_VertexSolid aVXS;
292 GEOMAlgo_WireSolid aWRS;
293 GEOMAlgo_ShellSolid aSHS;
294 GEOMAlgo_SolidSolid aSLS;
298 switch (myShapeType) {
309 aSLS.SetShape2(myArg2);
313 myErrorStatus=12; // unallowed subshape type
319 iErr=pSS->ErrorStatus();
321 myErrorStatus=32; // builder ShapeSolid failed
325 for (i=0; i<3; ++i) {
326 const TopTools_ListOfShape& aLS=pSS->Shapes(aSts[i]);
328 for (; aIt.More(); aIt.Next()) {
329 const TopoDS_Shape& aSImage=aIt.Value();
330 if (myImages.IsBound(aSImage)) {
331 const TopoDS_Shape& aSx=myImages.Find(aSImage);
332 myMSS.Add(aSx, aSts[i]);
335 myErrorStatus=33;// can not find original shape
341 //=======================================================================
342 //function : MakeArgument1
344 //=======================================================================
345 void GEOMAlgo_FinderShapeOn::MakeArgument1()
349 Standard_Integer i, aNb;
350 TopAbs_ShapeEnum aType;
351 BRepLib_FaceError aFErr;
352 BRepLib_MakeFace aMF;
353 TopTools_IndexedMapOfShape aM;
361 aMF.Init(mySurface, Standard_True);
363 if (aFErr!=BRepLib_FaceDone) {
364 myErrorStatus=20; // can not build the face
368 const TopoDS_Shape& aF=aMF.Shape();
369 aFace=TopoDS::Face(aF);
373 TopExp::MapShapes(aF, TopAbs_VERTEX, aM);
374 TopExp::MapShapes(aF, TopAbs_EDGE, aM);
376 for (i=1; i<=aNb; ++i) {
377 const TopoDS_Shape& aS=aM(i);
378 aType=aS.ShapeType();
380 case TopAbs_VERTEX: {
381 const TopoDS_Vertex& aVx=TopoDS::Vertex(aS);
382 aBB.UpdateVertex(aVx, myTolerance);
386 const TopoDS_Edge& aEx=TopoDS::Edge(aS);
387 aBB.UpdateEdge(aEx, myTolerance);
391 const TopoDS_Face& aFx=TopoDS::Face(aS);
392 aBB.UpdateFace(aFx, myTolerance);
401 aBB.MakeFace(aFace, mySurface, myTolerance);
411 //=======================================================================
412 //function : MakeArgument2
414 //=======================================================================
415 void GEOMAlgo_FinderShapeOn::MakeArgument2()
420 TopTools_DataMapOfShapeShape aOriginals;
424 GEOMAlgo_FinderShapeOn::CopySource(myShape, myImages, aOriginals, aSC);
428 //=======================================================================
429 //function : CheckData
431 //=======================================================================
432 void GEOMAlgo_FinderShapeOn::CheckData()
436 if(mySurface.IsNull()) {
437 myErrorStatus=10; // mySurface=NULL
441 if (myShape.IsNull()) {
442 myErrorStatus=11; // myShape=NULL
446 if (!(myShapeType==TopAbs_VERTEX ||
447 myShapeType==TopAbs_EDGE ||
448 myShapeType==TopAbs_FACE ||
449 myShapeType==TopAbs_SOLID)) {
450 myErrorStatus=12; // unallowed subshape type
454 if (myState==GEOMAlgo_ST_UNKNOWN ||
455 myState==GEOMAlgo_ST_INOUT) {
456 myErrorStatus=13; // unallowed state type
461 //=======================================================================
462 //function : CopySource
464 //=======================================================================
465 void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE,
466 TopTools_DataMapOfShapeShape& aImages,
467 TopTools_DataMapOfShapeShape& aOriginals,
470 Standard_Boolean bFree;
471 TopAbs_ShapeEnum aType;
476 aType=aE.ShapeType();
478 if (aOriginals.IsBound(aE)) {
479 aEx=aOriginals.ChangeFind(aE);
483 aEx=aE.EmptyCopied();
484 aOriginals.Bind(aE, aEx);
485 aImages.Bind(aEx, aE);
488 aR=(Standard_Integer)aType+1;
489 if (aR>TopAbs_VERTEX) {
494 aEx.Free(Standard_True);
496 aType=(TopAbs_ShapeEnum) aR;
498 aIt.Initialize(aE);//, Standard_False);
499 for (; aIt.More(); aIt.Next()) {
500 const TopoDS_Shape& aV=aIt.Value();
503 CopySource (aV, aImages, aOriginals, aVx);
505 aVx.Orientation(aV.Orientation());
515 // 10 -mySurface=NULL
517 // 12 -unallowed type of subshapes
518 // 13 -unallowed state
519 // 20 -can not build the face
520 // 30 -wrong args are used for DSFiller
521 // 31 -DSFiller failed
522 // 32 -builder ShapeSolid failed
523 // 33 -can not find original shape
527 // 10 -subshapes of type myShapeType can not be fond in myShape