1 // Created on: 2009-04-29
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2009-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRepCheck_Analyzer.hxx>
18 #include <BRepPrimAPI_MakeBox.hxx>
19 #include <DNaming.hxx>
20 #include <DNaming_BoxDriver.hxx>
21 #include <ModelDefinitions.hxx>
22 #include <Standard_Real.hxx>
23 #include <Standard_Type.hxx>
24 #include <TDataStd_Integer.hxx>
25 #include <TDataStd_Real.hxx>
26 #include <TDF_Label.hxx>
27 #include <TFunction_Function.hxx>
28 #include <TFunction_Logbook.hxx>
29 #include <TNaming.hxx>
30 #include <TNaming_Builder.hxx>
31 #include <TNaming_NamedShape.hxx>
32 #include <TopLoc_Location.hxx>
33 #include <TopoDS_Solid.hxx>
35 IMPLEMENT_STANDARD_RTTIEXT(DNaming_BoxDriver,TFunction_Driver)
37 //=======================================================================
38 //function : DNaming_BoxDriver
39 //purpose : Constructor
40 //=======================================================================
41 DNaming_BoxDriver::DNaming_BoxDriver()
44 //=======================================================================
46 //purpose : Validates labels of a function in <log>.
47 //=======================================================================
48 void DNaming_BoxDriver::Validate(Handle(TFunction_Logbook)&) const
51 //=======================================================================
52 //function : MustExecute
53 //purpose : Analyse in <log> if the loaded function must be executed
54 //=======================================================================
55 Standard_Boolean DNaming_BoxDriver::MustExecute(const Handle(TFunction_Logbook)&) const
60 //=======================================================================
62 //purpose : Execute the function and push in <log> the impacted labels
63 //=======================================================================
64 Standard_Integer DNaming_BoxDriver::Execute(Handle(TFunction_Logbook)& theLog) const
66 Handle(TFunction_Function) aFunction;
67 Label().FindAttribute(TFunction_Function::GetID(),aFunction);
68 if(aFunction.IsNull()) return -1;
72 // perform calculations
74 Standard_Real aDX = DNaming::GetReal(aFunction,BOX_DX)->Get();
75 Standard_Real aDY = DNaming::GetReal(aFunction,BOX_DY)->Get();
76 Standard_Real aDZ = DNaming::GetReal(aFunction,BOX_DZ)->Get();
78 Handle(TNaming_NamedShape) aPrevBox = DNaming::GetFunctionResult(aFunction);
80 TopLoc_Location aLocation;
81 if (!aPrevBox.IsNull() && !aPrevBox->IsEmpty()) {
82 aLocation = aPrevBox->Get().Location();
84 BRepPrimAPI_MakeBox aMakeBox(aDX, aDY, aDZ);
86 if (!aMakeBox.IsDone())
88 aFunction->SetFailure(ALGO_FAILED);
92 TopoDS_Shape aResult = aMakeBox.Solid();
93 BRepCheck_Analyzer aCheck(aResult);
94 if (!aCheck.IsValid (aResult))
96 aFunction->SetFailure(RESULT_NOT_VALID);
101 LoadNamingDS(RESPOSITION(aFunction),aMakeBox);
104 if(!aLocation.IsIdentity())
105 TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
107 theLog->SetValid(RESPOSITION(aFunction), Standard_True);
109 aFunction->SetFailure(DONE);
113 //=======================================================================
114 //function : LoadAndName
116 //=======================================================================
117 void DNaming_BoxDriver::LoadNamingDS (const TDF_Label& theResultLabel,
118 BRepPrimAPI_MakeBox& MS) const
120 TNaming_Builder Builder (theResultLabel);
121 Builder.Generated (MS.Solid());
123 //Load the faces of the box :
124 TopoDS_Face BottomFace = MS.BottomFace ();
125 TNaming_Builder BOF (theResultLabel.FindChild(1,Standard_True));
126 BOF.Generated (BottomFace);
128 TopoDS_Face TopFace = MS.TopFace ();
129 TNaming_Builder TF (theResultLabel.FindChild(2,Standard_True));
130 TF.Generated (TopFace);
132 TopoDS_Face FrontFace = MS.FrontFace ();
133 TNaming_Builder FF (theResultLabel.FindChild(3,Standard_True));
134 FF.Generated (FrontFace);
136 TopoDS_Face RightFace = MS.RightFace ();
137 TNaming_Builder RF (theResultLabel.FindChild(4,Standard_True));
138 RF.Generated (RightFace);
140 TopoDS_Face BackFace = MS.BackFace ();
141 TNaming_Builder BF (theResultLabel.FindChild(5,Standard_True));
142 BF.Generated (BackFace);
144 TopoDS_Face LeftFace = MS.LeftFace ();
145 TNaming_Builder LF (theResultLabel.FindChild(6,Standard_True));
146 LF.Generated (LeftFace);