// File: DNaming_PointDriver.cxx // Created: Thu Feb 25 18:49:04 2010 // Author: Sergey ZARITCHNY // Copyright: Open CasCade SA 2010 #include //OCCT #include #include #include #include #include #include #include #include // OCAF #include #include #include #include #include #include #include #include #include //======================================================================= //function : DNaming_PointDriver //purpose : Constructor //======================================================================= DNaming_PointDriver::DNaming_PointDriver() {} //======================================================================= //function : Validate //purpose : Validates labels of a function in . //======================================================================= void DNaming_PointDriver::Validate(TFunction_Logbook& theLog) const {} //======================================================================= //function : MustExecute //purpose : Analyse in if the loaded function must be executed //======================================================================= Standard_Boolean DNaming_PointDriver::MustExecute(const TFunction_Logbook& theLog) const { return Standard_True; } //======================================================================= //function : Execute //purpose : Execute the function and push in the impacted labels //======================================================================= Standard_Integer DNaming_PointDriver::Execute(TFunction_Logbook& theLog) const { Handle(TFunction_Function) aFunction; Label().FindAttribute(TFunction_Function::GetID(),aFunction); if(aFunction.IsNull()) return -1; // perform calculations Standard_Real aDX = DNaming::GetReal(aFunction,PNT_DX)->Get(); Standard_Real aDY = DNaming::GetReal(aFunction,PNT_DY)->Get(); Standard_Real aDZ = DNaming::GetReal(aFunction,PNT_DZ)->Get(); Handle(TNaming_NamedShape) aPrevPnt = DNaming::GetFunctionResult(aFunction); // Save location TopLoc_Location aLocation; if (!aPrevPnt.IsNull() && !aPrevPnt->IsEmpty()) { aLocation = aPrevPnt->Get().Location(); } gp_Pnt aPoint; if(aFunction->GetDriverGUID() == PNTRLT_GUID) { Handle(TDataStd_UAttribute) aRefPnt = DNaming::GetObjectArg(aFunction,PNTRLT_REF); Handle(TNaming_NamedShape) aRefPntNS = DNaming::GetObjectValue(aRefPnt); if (aRefPntNS.IsNull() || aRefPntNS->IsEmpty()) { #ifdef DEB cout<<"PointDriver:: Ref Point is empty"<SetFailure(WRONG_ARGUMENT); return -1; } TopoDS_Shape aRefPntShape = aRefPntNS->Get(); TopoDS_Vertex aVertex = TopoDS::Vertex(aRefPntShape); aPoint = BRep_Tool::Pnt(aVertex); aPoint.SetX(aPoint.X()+aDX); aPoint.SetY(aPoint.Y()+aDY); aPoint.SetZ(aPoint.Z()+aDZ); } else aPoint = gp_Pnt(aDX, aDY, aDZ); BRepBuilderAPI_MakeVertex aMakeVertex(aPoint); if(!aMakeVertex.IsDone()) { aFunction->SetFailure(ALGO_FAILED); return -1; } // Naming const TDF_Label& aResultLabel = RESPOSITION(aFunction); TNaming_Builder aBuilder(aResultLabel); aBuilder.Generated(aMakeVertex.Shape()); // restore location if(!aLocation.IsIdentity()) TNaming::Displace(aResultLabel, aLocation, Standard_True); theLog.SetValid(aResultLabel, Standard_True); aFunction->SetFailure(DONE); return 0; }