Salome HOME
PAL8395: Fix pb. with bug2extraEdges.py
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PipeDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_PipeDriver.hxx"
4 #include "GEOMImpl_IPipe.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRep_Tool.hxx>
9 #include <BRepCheck_Analyzer.hxx>
10 #include <BRepOffsetAPI_MakePipe.hxx>
11 #include <BRepBuilderAPI_MakeWire.hxx>
12
13 #include <TopAbs.hxx>
14 #include <TopoDS.hxx>
15 #include <TopoDS_Wire.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <TopoDS_Shape.hxx>
18
19 #include <Standard_NullObject.hxx>
20 #include <Standard_TypeMismatch.hxx>
21 #include <Standard_ConstructionError.hxx>
22
23 //=======================================================================
24 //function : GetID
25 //purpose  :
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
28 {
29   static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
30   return aPipeDriver;
31 }
32
33
34 //=======================================================================
35 //function : GEOMImpl_PipeDriver
36 //purpose  :
37 //=======================================================================
38 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
39 {
40 }
41
42 //=======================================================================
43 //function : Execute
44 //purpose  :
45 //=======================================================================
46 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
47 {
48   if (Label().IsNull()) return 0;
49   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
50
51   GEOMImpl_IPipe aCI (aFunction);
52   Standard_Integer aType = aFunction->GetType();
53
54   TopoDS_Shape aShape;
55
56   if (aType == PIPE_BASE_PATH) {
57     Handle(GEOM_Function) aRefBase = aCI.GetBase();
58     Handle(GEOM_Function) aRefPath = aCI.GetPath();
59     TopoDS_Shape aShapeBase = aRefBase->GetValue();
60     TopoDS_Shape aShapePath = aRefPath->GetValue();
61     if (aShapeBase.IsNull() || aShapePath.IsNull()) {
62       Standard_NullObject::Raise("MakePipe aborted : null shape argument");
63     }
64
65     // Get path contour
66     TopoDS_Wire aWire;
67     if (aShapePath.ShapeType() == TopAbs_WIRE) {
68       aWire = TopoDS::Wire(aShapePath);
69     } else {
70       if (aShapePath.ShapeType() == TopAbs_EDGE) {
71         TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
72         aWire = BRepBuilderAPI_MakeWire(anEdge);
73       } else {
74         Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
75       }
76     }
77
78     // Make pipe
79     aShape = BRepOffsetAPI_MakePipe(aWire, aShapeBase);
80   }
81   else {
82   }
83
84   if (aShape.IsNull()) return 0;
85
86   BRepCheck_Analyzer ana (aShape, Standard_False);
87   if (!ana.IsValid()) {
88     Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
89   }
90
91   aFunction->SetValue(aShape);
92
93   log.SetTouched(Label());
94
95   return 1;
96 }
97
98
99 //=======================================================================
100 //function :  GEOMImpl_PipeDriver_Type_
101 //purpose  :
102 //=======================================================================
103 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
104 {
105
106   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
107   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
108   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
109   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
110   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
111   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
112
113
114   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
115   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
116                                                          sizeof(GEOMImpl_PipeDriver),
117                                                          1,
118                                                          (Standard_Address)_Ancestors,
119                                                          (Standard_Address)NULL);
120
121   return _aType;
122 }
123
124 //=======================================================================
125 //function : DownCast
126 //purpose  :
127 //=======================================================================
128 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
129 {
130   Handle(GEOMImpl_PipeDriver) _anOtherObject;
131
132   if (!AnObject.IsNull()) {
133      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
134        _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
135      }
136   }
137
138   return _anOtherObject ;
139 }