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
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_PipeDriver.hxx>
24 #include <GEOMImpl_IPipe.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRepCheck_Analyzer.hxx>
30 #include <BRepOffsetAPI_MakePipe.hxx>
31 #include <BRepBuilderAPI_MakeWire.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <BRepOffsetAPI_MakePipeShell.hxx>
39 #include <TColStd_HSequenceOfTransient.hxx>
40 #include <GEOMImpl_IPipeDiffSect.hxx>
42 #include <Standard_NullObject.hxx>
43 #include <Standard_TypeMismatch.hxx>
44 #include <Standard_ConstructionError.hxx>
45 #include "utilities.h"
46 #include <TopExp_Explorer.hxx>
47 #include <TopTools_SequenceOfShape.hxx>
48 #include <BRep_Builder.hxx>
49 #include <TopoDS_Compound.hxx>
51 //=======================================================================
54 //=======================================================================
55 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
57 static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
62 //=======================================================================
63 //function : GEOMImpl_PipeDriver
65 //=======================================================================
66 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
70 //=======================================================================
73 //=======================================================================
74 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
76 if (Label().IsNull()) return 0;
77 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
78 GEOMImpl_IPipe* aCI= 0;
79 Standard_Integer aType = aFunction->GetType();
80 if(aType == PIPE_BASE_PATH)
81 aCI = new GEOMImpl_IPipe(aFunction);
82 else if(aType == PIPE_DIFFERENT_SECTIONS)
83 aCI = new GEOMImpl_IPipeDiffSect(aFunction);
87 Handle(GEOM_Function) aRefPath = aCI->GetPath();
88 TopoDS_Shape aShapePath = aRefPath->GetValue();
91 if (aShapePath.IsNull())
93 cout<<"Driver : path is null"<<endl;
95 Standard_NullObject::Raise("MakePipe aborted : null path argument");
99 TopoDS_Wire aWirePath;
100 if (aShapePath.ShapeType() == TopAbs_WIRE) {
101 aWirePath = TopoDS::Wire(aShapePath);
104 if (aShapePath.ShapeType() == TopAbs_EDGE) {
106 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
107 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
111 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
117 if (aType == PIPE_BASE_PATH)
120 Handle(GEOM_Function) aRefBase = aCI->GetBase();
122 TopoDS_Shape aShapeBase = aRefBase->GetValue();
124 if (aShapeBase.IsNull()) {
126 Standard_NullObject::Raise("MakePipe aborted : null base argument");
130 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
133 //building pipe with different sections
134 else if (aType == PIPE_DIFFERENT_SECTIONS)
136 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
137 //GEOMImpl_IPipeDiffSect* aCIDS = static_cast<GEOMImpl_IPipeDiffSect*>(aCI);
138 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
139 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
140 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
141 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
142 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
144 Standard_Integer i =1, nbBases = aBasesObjs->Length(),
145 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
147 if(nbLocs && nbLocs != nbBases)
150 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
152 TopTools_SequenceOfShape aSeqBases;
153 TopTools_SequenceOfShape aSeqLocs;
154 TopTools_SequenceOfShape aSeqFaces;
155 for( ; i <= nbBases; i++)
157 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
160 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
161 if(aRefBase.IsNull())
163 TopoDS_Shape aShapeBase = aRefBase->GetValue();
164 if(aShapeBase.IsNull())
166 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
168 //if for section was specified face with a few wires then a few
169 // pipes were build and make solid
170 if(aTypeBase == TopAbs_FACE)
172 //for case one path should be used other type function
173 aSeqFaces.Append(aShapeBase);
174 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
175 for( ; aExpW.More(); aExpW.Next())
177 TopoDS_Shape aWireProf = aExpW.Current();
178 aSeqBases.Append(aWireProf);
181 else if(aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX)
182 aSeqBases.Append(aShapeBase);
183 else if(aTypeBase == TopAbs_EDGE)
185 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
186 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
187 aSeqBases.Append(aWireProf);
191 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
192 if(anItemLoc.IsNull())
194 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
195 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
196 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
198 aSeqLocs.Append(aShapeLoc);
202 nbLocs = aSeqLocs.Length();
203 Standard_Integer nbShapes = aSeqBases.Length();
204 Standard_Integer step = nbShapes/nbBases;
206 if(nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases))
209 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
212 Standard_Integer ind =0;
213 for( i=1; i <= nbShapes && ind < nbShapes; i++) //i+nbBases <= nbShapes
215 TopTools_SequenceOfShape usedBases;
216 Standard_Integer j = 1;
217 for( ; j <= nbBases ; j++)
219 ind = i + (j-1)*step;
221 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
222 usedBases.Append(aWireProf);
225 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
226 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
227 aBuilder.Add(aWireProf,aVert,aWithContact,aWithCorrect);
230 aBuilder.Add(aWireProf,aWithContact,aWithCorrect);
232 if(!aBuilder.IsReady())
235 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
238 aShape = aBuilder.Shape();
239 aSeqFaces.Append(aShape);
240 for( j = 1; j <=usedBases.Length(); j++)
241 aBuilder.Delete(usedBases.Value(j));
244 //for case if section is face
245 if(aSeqFaces.Length() >1)
248 TopoDS_Compound aComp;
249 aB.MakeCompound(aComp);
250 for( i = 1; i <= aSeqFaces.Length(); i++)
251 aB.Add(aComp,aSeqFaces.Value(i));
255 if (aShape.IsNull()) return 0;
257 BRepCheck_Analyzer ana (aShape, Standard_False);
258 if (!ana.IsValid()) {
260 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
263 aFunction->SetValue(aShape);
265 log.SetTouched(Label());
271 //=======================================================================
272 //function : GEOMImpl_PipeDriver_Type_
274 //=======================================================================
275 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
278 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
279 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
280 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
281 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
282 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
283 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
286 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
287 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
288 sizeof(GEOMImpl_PipeDriver),
290 (Standard_Address)_Ancestors,
291 (Standard_Address)NULL);
296 //=======================================================================
297 //function : DownCast
299 //=======================================================================
300 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
302 Handle(GEOMImpl_PipeDriver) _anOtherObject;
304 if (!AnObject.IsNull()) {
305 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
306 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
310 return _anOtherObject ;