Warnings on vc14 were eliminated
[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_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>
35
36 IMPLEMENT_STANDARD_RTTIEXT(DNaming_BoxDriver,TFunction_Driver)
37
38 //=======================================================================
39 //function : DNaming_BoxDriver
40 //purpose  : Constructor
41 //=======================================================================
42 DNaming_BoxDriver::DNaming_BoxDriver()
43 {}
44
45 //=======================================================================
46 //function : Validate
47 //purpose  : Validates labels of a function in <log>.
48 //=======================================================================
49 void DNaming_BoxDriver::Validate(Handle(TFunction_Logbook)&) const
50 {}
51
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
57 {
58   return Standard_True;
59 }
60
61 //=======================================================================
62 //function : Execute
63 //purpose  : Execute the function and push in <log> the impacted labels
64 //=======================================================================
65 Standard_Integer DNaming_BoxDriver::Execute(Handle(TFunction_Logbook)& theLog) const
66 {
67   Handle(TFunction_Function) aFunction;
68   Label().FindAttribute(TFunction_Function::GetID(),aFunction);
69   if(aFunction.IsNull()) return -1;
70   
71   
72   
73 // perform calculations
74
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();
78
79   Handle(TNaming_NamedShape) aPrevBox = DNaming::GetFunctionResult(aFunction);
80 // Save location
81   TopLoc_Location aLocation;
82   if (!aPrevBox.IsNull() && !aPrevBox->IsEmpty()) {
83     aLocation = aPrevBox->Get().Location();
84   }
85   BRepPrimAPI_MakeBox aMakeBox(aDX, aDY, aDZ);  
86   aMakeBox.Build();
87   if (!aMakeBox.IsDone())
88     {
89       aFunction->SetFailure(ALGO_FAILED);
90       return -1;
91     }
92
93   TopoDS_Shape aResult = aMakeBox.Solid();
94   BRepCheck_Analyzer aCheck(aResult);
95   if (!aCheck.IsValid (aResult))
96     {
97       aFunction->SetFailure(RESULT_NOT_VALID);
98       return -1;
99     }
100
101     // Naming
102   LoadNamingDS(RESPOSITION(aFunction),aMakeBox);
103
104 // restore location
105   if(!aLocation.IsIdentity())
106     TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
107
108   theLog->SetValid(RESPOSITION(aFunction), Standard_True);  
109
110   aFunction->SetFailure(DONE);
111   return 0;
112 }
113
114 //=======================================================================
115 //function : LoadAndName
116 //purpose  : 
117 //=======================================================================
118 void DNaming_BoxDriver::LoadNamingDS (const TDF_Label& theResultLabel, 
119                                       BRepPrimAPI_MakeBox& MS) const 
120 {
121   TNaming_Builder Builder (theResultLabel);
122   Builder.Generated (MS.Solid());
123
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);
128  
129   TopoDS_Face TopFace = MS.TopFace ();
130   TNaming_Builder TF (theResultLabel.FindChild(2,Standard_True)); 
131   TF.Generated (TopFace); 
132
133   TopoDS_Face FrontFace = MS.FrontFace ();
134   TNaming_Builder FF (theResultLabel.FindChild(3,Standard_True)); 
135   FF.Generated (FrontFace); 
136
137   TopoDS_Face RightFace = MS.RightFace ();
138   TNaming_Builder RF (theResultLabel.FindChild(4,Standard_True)); 
139   RF.Generated (RightFace); 
140
141   TopoDS_Face BackFace = MS.BackFace ();
142   TNaming_Builder BF (theResultLabel.FindChild(5,Standard_True)); 
143   BF.Generated (BackFace); 
144
145   TopoDS_Face LeftFace = MS.LeftFace ();
146   TNaming_Builder LF (theResultLabel.FindChild(6,Standard_True)); 
147   LF.Generated (LeftFace); 
148 }