0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / DNaming / DNaming_PointDriver.cxx
1 // Created on: 2010-02-25
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2010-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 #include <DNaming_PointDriver.ixx>
17 //OCCT
18 #include <BRepBuilderAPI_MakeVertex.hxx>
19 #include <TopLoc_Location.hxx>
20 #include <TopoDS_Shape.hxx>
21 #include <TopoDS_Vertex.hxx>
22 #include <TopoDS.hxx>
23 #include <BRep_Tool.hxx>
24 #include <gp_Pnt.hxx>
25 #include <Standard_GUID.hxx>
26 // OCAF
27 #include <TNaming.hxx>
28 #include <TDF_Label.hxx>
29 #include <TDataStd_Real.hxx>
30 #include <TFunction_Logbook.hxx>
31 #include <TFunction_Function.hxx>
32 #include <TNaming_NamedShape.hxx>
33 #include <TNaming_Builder.hxx>
34
35 #include <DNaming.hxx>
36 #include <ModelDefinitions.hxx>
37
38 //=======================================================================
39 //function : DNaming_PointDriver
40 //purpose  : Constructor
41 //=======================================================================
42 DNaming_PointDriver::DNaming_PointDriver()
43 {}
44
45 //=======================================================================
46 //function : Validate
47 //purpose  : Validates labels of a function in <log>.
48 //=======================================================================
49 void DNaming_PointDriver::Validate(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_PointDriver::MustExecute(const 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_PointDriver::Execute(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 // perform calculations
72
73   Standard_Real aDX = DNaming::GetReal(aFunction,PNT_DX)->Get();
74   Standard_Real aDY = DNaming::GetReal(aFunction,PNT_DY)->Get();
75   Standard_Real aDZ = DNaming::GetReal(aFunction,PNT_DZ)->Get();
76
77   Handle(TNaming_NamedShape) aPrevPnt = DNaming::GetFunctionResult(aFunction);
78 // Save location
79   TopLoc_Location aLocation;
80   if (!aPrevPnt.IsNull() && !aPrevPnt->IsEmpty()) {
81     aLocation = aPrevPnt->Get().Location();
82   }
83   gp_Pnt aPoint;
84   if(aFunction->GetDriverGUID() == PNTRLT_GUID) {
85     Handle(TDataStd_UAttribute) aRefPnt = DNaming::GetObjectArg(aFunction,PNTRLT_REF);
86     Handle(TNaming_NamedShape) aRefPntNS = DNaming::GetObjectValue(aRefPnt);
87     if (aRefPntNS.IsNull() || aRefPntNS->IsEmpty()) {
88 #ifdef DNAMING_DEB
89       cout<<"PointDriver:: Ref Point is empty"<<endl;
90 #endif
91       aFunction->SetFailure(WRONG_ARGUMENT);
92       return -1;
93     }
94     TopoDS_Shape aRefPntShape = aRefPntNS->Get();
95     TopoDS_Vertex aVertex = TopoDS::Vertex(aRefPntShape);
96     aPoint = BRep_Tool::Pnt(aVertex);
97     aPoint.SetX(aPoint.X()+aDX);
98     aPoint.SetY(aPoint.Y()+aDY);
99     aPoint.SetZ(aPoint.Z()+aDZ);
100   } else 
101     aPoint = gp_Pnt(aDX, aDY, aDZ);
102
103   BRepBuilderAPI_MakeVertex aMakeVertex(aPoint);
104
105   if(!aMakeVertex.IsDone()) {
106     aFunction->SetFailure(ALGO_FAILED);
107     return -1;
108   }
109
110   // Naming
111   const TDF_Label& aResultLabel = RESPOSITION(aFunction);
112   TNaming_Builder aBuilder(aResultLabel);
113   aBuilder.Generated(aMakeVertex.Shape());
114   
115   // restore location
116   if(!aLocation.IsIdentity())
117     TNaming::Displace(aResultLabel, aLocation, Standard_True);
118
119   theLog.SetValid(aResultLabel, Standard_True);  
120   
121   aFunction->SetFailure(DONE);
122   return 0;
123 }