1 // Copyright (c) 2020 OPEN CASCADE SAS
3 // This file is part of the examples of the Open CASCADE Technology software library.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
22 #include "TOcafFunction_CylDriver.h"
24 #include <BRepPrimAPI_MakeCylinder.hxx>
25 #include <Standard_GUID.hxx>
26 #include <TCollection_AsciiString.hxx>
27 #include <TDF_Tool.hxx>
28 #include <TDataStd_Real.hxx>
29 #include <TNaming_Builder.hxx>
31 //=======================================================================
34 //=======================================================================
35 const Standard_GUID& TOcafFunction_CylDriver::GetID()
37 static const Standard_GUID anID("22D22E53-D69A-11d4-8F1A-0060B0EE18E8");
41 //=======================================================================
42 //function : TPartStd_CylDriver
44 //=======================================================================
45 TOcafFunction_CylDriver::TOcafFunction_CylDriver()
50 //=======================================================================
53 //=======================================================================
54 void TOcafFunction_CylDriver::Validate (Handle(TFunction_Logbook)& log) const
56 // We validate the object label ( Label() ), all the arguments and the results of the object:
57 log->SetValid(Label(), Standard_True);
60 //=======================================================================
61 //function : MustExecute
63 //=======================================================================
64 Standard_Boolean TOcafFunction_CylDriver::MustExecute(const Handle(TFunction_Logbook)& log) const
66 // If the object's label is modified:
67 if (log->IsModified(Label())) return Standard_True;
69 // Cylinder (in our simple case) has 5 arguments:
72 if (log->IsModified(Label().FindChild(1)))
74 return Standard_True; // radius.
76 if (log->IsModified(Label().FindChild(2)))
78 return Standard_True; // height,
80 if (log->IsModified(Label().FindChild(3)))
82 return Standard_True; // x.
84 if (log->IsModified(Label().FindChild(4)))
86 return Standard_True; // y,
88 if (log->IsModified(Label().FindChild(5)))
90 return Standard_True; // z.
92 // if there are no any modifications concerned the Cyl,
93 // it's not necessary to recompute (to call the method Execute()):
94 return Standard_False;
97 //=======================================================================
100 //=======================================================================
101 Standard_Integer TOcafFunction_CylDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
103 // Get the values of dimension and position attributes
104 Handle(TDataStd_Real) TSR;
105 Standard_Real x, y, z, r, h;
106 if (!Label().FindChild(1).FindAttribute(TDataStd_Real::GetID(), TSR))
112 if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR))
118 if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR))
124 if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR))
130 if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR))
136 // Build a Cyl using the dimension and position attributes
137 BRepPrimAPI_MakeCylinder mkCyl(gp_Ax2(gp_Pnt(x, y, z), gp_Dir(0, 0, 1)), r, h);
138 TopoDS_Shape ResultShape = mkCyl.Shape();
141 // Build a TNaming_NamedShape using built Cyl
142 TNaming_Builder B(Label());
143 B.Generated(ResultShape);
145 // If there are no any mistakes we return 0: