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