0032806: Coding - get rid of unused headers [Contap to Extrema]
[occt.git] / src / DNaming / DNaming_BoxDriver.cxx
1 // Created on: 2009-04-29
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2009-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
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>
34
35 IMPLEMENT_STANDARD_RTTIEXT(DNaming_BoxDriver,TFunction_Driver)
36
37 //=======================================================================
38 //function : DNaming_BoxDriver
39 //purpose  : Constructor
40 //=======================================================================
41 DNaming_BoxDriver::DNaming_BoxDriver()
42 {}
43
44 //=======================================================================
45 //function : Validate
46 //purpose  : Validates labels of a function in <log>.
47 //=======================================================================
48 void DNaming_BoxDriver::Validate(Handle(TFunction_Logbook)&) const
49 {}
50
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
56 {
57   return Standard_True;
58 }
59
60 //=======================================================================
61 //function : Execute
62 //purpose  : Execute the function and push in <log> the impacted labels
63 //=======================================================================
64 Standard_Integer DNaming_BoxDriver::Execute(Handle(TFunction_Logbook)& theLog) const
65 {
66   Handle(TFunction_Function) aFunction;
67   Label().FindAttribute(TFunction_Function::GetID(),aFunction);
68   if(aFunction.IsNull()) return -1;
69   
70   
71   
72 // perform calculations
73
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();
77
78   Handle(TNaming_NamedShape) aPrevBox = DNaming::GetFunctionResult(aFunction);
79 // Save location
80   TopLoc_Location aLocation;
81   if (!aPrevBox.IsNull() && !aPrevBox->IsEmpty()) {
82     aLocation = aPrevBox->Get().Location();
83   }
84   BRepPrimAPI_MakeBox aMakeBox(aDX, aDY, aDZ);  
85   aMakeBox.Build();
86   if (!aMakeBox.IsDone())
87     {
88       aFunction->SetFailure(ALGO_FAILED);
89       return -1;
90     }
91
92   TopoDS_Shape aResult = aMakeBox.Solid();
93   BRepCheck_Analyzer aCheck(aResult);
94   if (!aCheck.IsValid (aResult))
95     {
96       aFunction->SetFailure(RESULT_NOT_VALID);
97       return -1;
98     }
99
100     // Naming
101   LoadNamingDS(RESPOSITION(aFunction),aMakeBox);
102
103 // restore location
104   if(!aLocation.IsIdentity())
105     TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
106
107   theLog->SetValid(RESPOSITION(aFunction), Standard_True);  
108
109   aFunction->SetFailure(DONE);
110   return 0;
111 }
112
113 //=======================================================================
114 //function : LoadAndName
115 //purpose  : 
116 //=======================================================================
117 void DNaming_BoxDriver::LoadNamingDS (const TDF_Label& theResultLabel, 
118                                       BRepPrimAPI_MakeBox& MS) const 
119 {
120   TNaming_Builder Builder (theResultLabel);
121   Builder.Generated (MS.Solid());
122
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);
127  
128   TopoDS_Face TopFace = MS.TopFace ();
129   TNaming_Builder TF (theResultLabel.FindChild(2,Standard_True)); 
130   TF.Generated (TopFace); 
131
132   TopoDS_Face FrontFace = MS.FrontFace ();
133   TNaming_Builder FF (theResultLabel.FindChild(3,Standard_True)); 
134   FF.Generated (FrontFace); 
135
136   TopoDS_Face RightFace = MS.RightFace ();
137   TNaming_Builder RF (theResultLabel.FindChild(4,Standard_True)); 
138   RF.Generated (RightFace); 
139
140   TopoDS_Face BackFace = MS.BackFace ();
141   TNaming_Builder BF (theResultLabel.FindChild(5,Standard_True)); 
142   BF.Generated (BackFace); 
143
144   TopoDS_Face LeftFace = MS.LeftFace ();
145   TNaming_Builder LF (theResultLabel.FindChild(6,Standard_True)); 
146   LF.Generated (LeftFace); 
147 }