X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPrimitivesPlugin%2FPrimitivesPlugin_Sphere.cpp;h=0c4b38f4078d9b07c45cf7cef5b8c718f00ab3fc;hb=06e7f5859095193fc7f498bd89a7d28009794f53;hp=00ca224b09375f01193c573a8803fb105a41fe9a;hpb=745c72679f6346375d5e886b25cc3865f3c4daae;p=modules%2Fshaper.git diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp index 00ca224b0..0c4b38f40 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2021 CEA/DEN, EDF R&D +// Copyright (C) 2017-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -17,7 +17,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File: PrimitivesPlugin_Sphere.h +// File: PrimitivesPlugin_Sphere.cpp // Created: 15 Mar 2017 // Author: Clarisse Genrault (CEA) @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,10 @@ PrimitivesPlugin_Sphere::PrimitivesPlugin_Sphere() //================================================================================================= void PrimitivesPlugin_Sphere::initAttributes() { + data()->addAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD(), + ModelAPI_AttributeString::typeId()); + + // data for the first mode : by a point and a radius data()->addAttribute(PrimitivesPlugin_Sphere::CENTER_POINT_ID(), ModelAPI_AttributeSelection::typeId()); @@ -60,10 +65,32 @@ void PrimitivesPlugin_Sphere::initAttributes() aCenterPoint->setValue(aPointRes, std::shared_ptr()); } } + + // data for the second mode : by dimensions + data()->addAttribute(PrimitivesPlugin_Sphere::RMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::RMAX_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::PHIMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::PHIMAX_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::THETAMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::THETAMAX_ID(), ModelAPI_AttributeDouble::typeId()); } //================================================================================================= void PrimitivesPlugin_Sphere::execute() +{ + AttributeStringPtr aMethodTypeAttr = string(PrimitivesPlugin_Sphere::CREATION_METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + + if (aMethodType == CREATION_METHOD_BY_PT_RADIUS()) + createSphereByPtRadius(); + + if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) + createShereByDimensions(); +} + + +//================================================================================================= +void PrimitivesPlugin_Sphere::createSphereByPtRadius() { // Getting point. std::shared_ptr aCenterPoint; @@ -95,7 +122,7 @@ void PrimitivesPlugin_Sphere::execute() // Build the sphere aSphereAlgo->build(); - // Check if the creation of the cylinder + // Check if the creation of the sphere is OK if(!aSphereAlgo->isDone()) { setError(aSphereAlgo->getError()); return; @@ -111,6 +138,48 @@ void PrimitivesPlugin_Sphere::execute() setResult(aResultBox, aResultIndex); } +//================================================================================================= +void PrimitivesPlugin_Sphere::createShereByDimensions() +{ + // Getting rmin, rmax, phimin, phimax, thetamin et thetamax + double aRMin = real(PrimitivesPlugin_Sphere::RMIN_ID())->value(); + double aRMax = real(PrimitivesPlugin_Sphere::RMAX_ID())->value(); + double aPhiMin = real(PrimitivesPlugin_Sphere::PHIMIN_ID())->value(); + double aPhiMax = real(PrimitivesPlugin_Sphere::PHIMAX_ID())->value(); + double aThetaMin = real(PrimitivesPlugin_Sphere::THETAMIN_ID())->value(); + double aThetaMax = real(PrimitivesPlugin_Sphere::THETAMAX_ID())->value(); + + std::shared_ptr aSphereAlgo = std::shared_ptr( + new GeomAlgoAPI_Sphere(aRMin, aRMax, aPhiMin, aPhiMax, aThetaMin, aThetaMax)); + + // These checks should be made to the GUI for the feature but + // the corresponding validator does not exist yet. + if (!aSphereAlgo->check()) { + setError(aSphereAlgo->getError()); + return; + } + + // Build the sphere + aSphereAlgo->build(); + + // Check if the creation of the sphere is OK + if(!aSphereAlgo->isDone()) { + // The error is not displayed in a popup window. It must be in the message console. + setError(aSphereAlgo->getError()); + return; + } + if(!aSphereAlgo->checkValid("Sphere Builder")) { + // The error is not displayed in a popup window. It must be in the message console. + setError(aSphereAlgo->getError()); + return; + } + + int aResultIndex = 0; + ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); + loadNamingDS(aSphereAlgo, aResultBox); + setResult(aResultBox, aResultIndex); +} + //================================================================================================= void PrimitivesPlugin_Sphere::loadNamingDS(std::shared_ptr theSphereAlgo, std::shared_ptr theResultSphere)