Salome HOME
Copyright update 2022
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PipePathDriver.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <GEOMImpl_PipePathDriver.hxx>
24 #include <GEOMImpl_ShapeDriver.hxx>
25 #include <GEOMImpl_IPipePath.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
28
29 #include <BRepOffsetAPI_MiddlePath.hxx>
30 #include <TColStd_HSequenceOfTransient.hxx>
31 #include <Precision.hxx>
32 #include <Standard_NullObject.hxx>
33
34 //=======================================================================
35 //function : GetID
36 //purpose  :
37 //=======================================================================
38 const Standard_GUID& GEOMImpl_PipePathDriver::GetID()
39 {
40   static Standard_GUID aPipePathDriver ("FF1BBB19-5D14-4df2-980B-3A668264EA17");
41   return aPipePathDriver;
42 }
43
44 //=======================================================================
45 //function : GEOMImpl_PipePathDriver
46 //purpose  :
47 //=======================================================================
48 GEOMImpl_PipePathDriver::GEOMImpl_PipePathDriver()
49 {
50 }
51
52 //=======================================================================
53 //function : Execute
54 //purpose  :
55 //=======================================================================
56 Standard_Integer GEOMImpl_PipePathDriver::Execute(Handle(TFunction_Logbook)& log) const
57 {
58   if (Label().IsNull()) return 0;
59   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
60   Standard_Integer aType = aFunction->GetType();
61
62   TopoDS_Shape aRes;
63
64   // RestorePath
65   if (aType == PIPE_PATH_TWO_BASES) {
66     GEOMImpl_IPipePath aPI (aFunction);
67
68     Handle(GEOM_Function) aRefShape = aPI.GetShape();
69     Handle(GEOM_Function) aRefBase1 = aPI.GetBase1();
70     Handle(GEOM_Function) aRefBase2 = aPI.GetBase2();
71
72     TopoDS_Shape aShape = aRefShape->GetValue();
73     TopoDS_Shape aBase1 = aRefBase1->GetValue();
74     TopoDS_Shape aBase2 = aRefBase2->GetValue();
75
76     if (aShape.IsNull() || aBase1.IsNull() || aBase2.IsNull())
77       Standard_NullObject::Raise("RestorePath aborted : null argument");
78
79     BRepOffsetAPI_MiddlePath aMPB (aShape, aBase1, aBase2);
80     aMPB.Build();
81     if (aMPB.IsDone()) {
82       aRes = aMPB.Shape();
83     }
84   }
85   else if (aType == PIPE_PATH_TWO_SEQS) {
86     GEOMImpl_IPipePath aPI (aFunction);
87
88     Handle(GEOM_Function) aRefShape = aPI.GetShape();
89     TopoDS_Shape aShape = aRefShape->GetValue();
90
91     Handle(TColStd_HSequenceOfTransient) aBaseSeq1 = aPI.GetBaseSeq1();
92     Handle(TColStd_HSequenceOfTransient) aBaseSeq2 = aPI.GetBaseSeq2();
93
94     TopoDS_Shape aBase1;
95     TopoDS_Shape aBase2;
96
97     if (aBaseSeq1->Length() == 1 && aBaseSeq2->Length() == 1) {
98       Handle(GEOM_Function) aRefShape1 = Handle(GEOM_Function)::DownCast(aBaseSeq1->Value(1));
99       Handle(GEOM_Function) aRefShape2 = Handle(GEOM_Function)::DownCast(aBaseSeq2->Value(1));
100       aBase1 = aRefShape1->GetValue();
101       aBase2 = aRefShape2->GetValue();
102     }
103     else {
104       aBase1 = GEOMImpl_ShapeDriver::MakeWireFromEdges(aBaseSeq1, Precision::Confusion());
105       aBase2 = GEOMImpl_ShapeDriver::MakeWireFromEdges(aBaseSeq2, Precision::Confusion());
106     }
107
108     if (aShape.IsNull() || aBase1.IsNull() || aBase2.IsNull())
109       Standard_NullObject::Raise("RestorePath aborted : null argument");
110
111     BRepOffsetAPI_MiddlePath aMPB (aShape, aBase1, aBase2);
112     aMPB.Build();
113     if (aMPB.IsDone()) {
114       aRes = aMPB.Shape();
115     }
116   }
117   else {
118   }
119
120   if (aRes.IsNull()) return 0;
121
122   aFunction->SetValue(aRes);
123   log->SetTouched(Label());
124
125   return 1;
126 }
127
128 //================================================================================
129 /*!
130  * \brief Returns a name of creation operation and names and values of creation parameters
131  */
132 //================================================================================
133
134 bool GEOMImpl_PipePathDriver::
135 GetCreationInformation(std::string&             theOperationName,
136                        std::vector<GEOM_Param>& theParams)
137 {
138   if (Label().IsNull()) return 0;
139   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
140
141   GEOMImpl_IPipePath aCI( function );
142   Standard_Integer aType = function->GetType();
143
144   theOperationName = "PIPE_PATH";
145
146   switch ( aType ) {
147   case PIPE_PATH_TWO_BASES:
148     AddParam( theParams, "Pipe-like object", aCI.GetShape() );
149     AddParam( theParams, "First base", aCI.GetBase1() );
150     AddParam( theParams, "Second base", aCI.GetBase2() );
151     break;
152   case PIPE_PATH_TWO_SEQS:
153     AddParam( theParams, "Pipe-like object", aCI.GetShape() );
154     AddParam( theParams, "First bases", aCI.GetBaseSeq1() );
155     AddParam( theParams, "Second bases", aCI.GetBaseSeq2() );
156     break;
157   default:
158     return false;
159   }
160   
161   return true;
162 }
163
164 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_PipePathDriver,GEOM_BaseDriver)