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_GUID.hxx>
23 #include <Standard_Real.hxx>
24 #include <Standard_Type.hxx>
25 #include <TDataStd_Integer.hxx>
26 #include <TDataStd_Real.hxx>
27 #include <TDF_Label.hxx>
28 #include <TFunction_Function.hxx>
29 #include <TFunction_Logbook.hxx>
30 #include <TNaming.hxx>
31 #include <TNaming_Builder.hxx>
32 #include <TNaming_NamedShape.hxx>
33 #include <TopLoc_Location.hxx>
34 #include <TopoDS_Solid.hxx>
36 IMPLEMENT_STANDARD_RTTIEXT(DNaming_BoxDriver,TFunction_Driver)
38 //=======================================================================
39 //function : DNaming_BoxDriver
40 //purpose : Constructor
41 //=======================================================================
42 DNaming_BoxDriver::DNaming_BoxDriver()
45 //=======================================================================
47 //purpose : Validates labels of a function in <log>.
48 //=======================================================================
49 void DNaming_BoxDriver::Validate(Handle(TFunction_Logbook)&) const
52 //=======================================================================
53 //function : MustExecute
54 //purpose : Analyse in <log> if the loaded function must be executed
55 //=======================================================================
56 Standard_Boolean DNaming_BoxDriver::MustExecute(const Handle(TFunction_Logbook)&) const
61 //=======================================================================
63 //purpose : Execute the function and push in <log> the impacted labels
64 //=======================================================================
65 Standard_Integer DNaming_BoxDriver::Execute(Handle(TFunction_Logbook)& theLog) const
67 Handle(TFunction_Function) aFunction;
68 Label().FindAttribute(TFunction_Function::GetID(),aFunction);
69 if(aFunction.IsNull()) return -1;
73 // perform calculations
75 Standard_Real aDX = DNaming::GetReal(aFunction,BOX_DX)->Get();
76 Standard_Real aDY = DNaming::GetReal(aFunction,BOX_DY)->Get();
77 Standard_Real aDZ = DNaming::GetReal(aFunction,BOX_DZ)->Get();
79 Handle(TNaming_NamedShape) aPrevBox = DNaming::GetFunctionResult(aFunction);
81 TopLoc_Location aLocation;
82 if (!aPrevBox.IsNull() && !aPrevBox->IsEmpty()) {
83 aLocation = aPrevBox->Get().Location();
85 BRepPrimAPI_MakeBox aMakeBox(aDX, aDY, aDZ);
87 if (!aMakeBox.IsDone())
89 aFunction->SetFailure(ALGO_FAILED);
93 TopoDS_Shape aResult = aMakeBox.Solid();
94 BRepCheck_Analyzer aCheck(aResult);
95 if (!aCheck.IsValid (aResult))
97 aFunction->SetFailure(RESULT_NOT_VALID);
102 LoadNamingDS(RESPOSITION(aFunction),aMakeBox);
105 if(!aLocation.IsIdentity())
106 TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
108 theLog->SetValid(RESPOSITION(aFunction), Standard_True);
110 aFunction->SetFailure(DONE);
114 //=======================================================================
115 //function : LoadAndName
117 //=======================================================================
118 void DNaming_BoxDriver::LoadNamingDS (const TDF_Label& theResultLabel,
119 BRepPrimAPI_MakeBox& MS) const
121 TNaming_Builder Builder (theResultLabel);
122 Builder.Generated (MS.Solid());
124 //Load the faces of the box :
125 TopoDS_Face BottomFace = MS.BottomFace ();
126 TNaming_Builder BOF (theResultLabel.FindChild(1,Standard_True));
127 BOF.Generated (BottomFace);
129 TopoDS_Face TopFace = MS.TopFace ();
130 TNaming_Builder TF (theResultLabel.FindChild(2,Standard_True));
131 TF.Generated (TopFace);
133 TopoDS_Face FrontFace = MS.FrontFace ();
134 TNaming_Builder FF (theResultLabel.FindChild(3,Standard_True));
135 FF.Generated (FrontFace);
137 TopoDS_Face RightFace = MS.RightFace ();
138 TNaming_Builder RF (theResultLabel.FindChild(4,Standard_True));
139 RF.Generated (RightFace);
141 TopoDS_Face BackFace = MS.BackFace ();
142 TNaming_Builder BF (theResultLabel.FindChild(5,Standard_True));
143 BF.Generated (BackFace);
145 TopoDS_Face LeftFace = MS.LeftFace ();
146 TNaming_Builder LF (theResultLabel.FindChild(6,Standard_True));
147 LF.Generated (LeftFace);