1 // Created on: 2010-02-25
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2010-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.
16 #include <DNaming_PointDriver.ixx>
18 #include <BRepBuilderAPI_MakeVertex.hxx>
19 #include <TopLoc_Location.hxx>
20 #include <TopoDS_Shape.hxx>
21 #include <TopoDS_Vertex.hxx>
23 #include <BRep_Tool.hxx>
25 #include <Standard_GUID.hxx>
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>
35 #include <DNaming.hxx>
36 #include <ModelDefinitions.hxx>
38 //=======================================================================
39 //function : DNaming_PointDriver
40 //purpose : Constructor
41 //=======================================================================
42 DNaming_PointDriver::DNaming_PointDriver()
45 //=======================================================================
47 //purpose : Validates labels of a function in <log>.
48 //=======================================================================
49 void DNaming_PointDriver::Validate(TFunction_Logbook&) const
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
61 //=======================================================================
63 //purpose : Execute the function and push in <log> the impacted labels
64 //=======================================================================
65 Standard_Integer DNaming_PointDriver::Execute(TFunction_Logbook& theLog) const
67 Handle(TFunction_Function) aFunction;
68 Label().FindAttribute(TFunction_Function::GetID(),aFunction);
69 if(aFunction.IsNull()) return -1;
71 // perform calculations
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();
77 Handle(TNaming_NamedShape) aPrevPnt = DNaming::GetFunctionResult(aFunction);
79 TopLoc_Location aLocation;
80 if (!aPrevPnt.IsNull() && !aPrevPnt->IsEmpty()) {
81 aLocation = aPrevPnt->Get().Location();
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()) {
89 cout<<"PointDriver:: Ref Point is empty"<<endl;
91 aFunction->SetFailure(WRONG_ARGUMENT);
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);
101 aPoint = gp_Pnt(aDX, aDY, aDZ);
103 BRepBuilderAPI_MakeVertex aMakeVertex(aPoint);
105 if(!aMakeVertex.IsDone()) {
106 aFunction->SetFailure(ALGO_FAILED);
111 const TDF_Label& aResultLabel = RESPOSITION(aFunction);
112 TNaming_Builder aBuilder(aResultLabel);
113 aBuilder.Generated(aMakeVertex.Shape());
116 if(!aLocation.IsIdentity())
117 TNaming::Displace(aResultLabel, aLocation, Standard_True);
119 theLog.SetValid(aResultLabel, Standard_True);
121 aFunction->SetFailure(DONE);