X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesAPI%2FFeaturesAPI_Translation.cpp;h=f3243c1a2a7edf9ea3062be99095a42e0f5d50be;hb=88ee9b2b81cf93a6324336b57e30cc8a3a487499;hp=e4c61d95458f096f6fd55c726784f1b5f304078c;hpb=41a0b4ccfdd7ab5ede8dbdb2b2445ab6cfbc2662;p=modules%2Fshaper.git diff --git a/src/FeaturesAPI/FeaturesAPI_Translation.cpp b/src/FeaturesAPI/FeaturesAPI_Translation.cpp index e4c61d954..f3243c1a2 100644 --- a/src/FeaturesAPI/FeaturesAPI_Translation.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Translation.cpp @@ -1,31 +1,75 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: FeaturesAPI_Translation.cpp -// Created: 07 June 2016 -// Author: Dmitry Bobylev +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "FeaturesAPI_Translation.h" +#include #include //================================================================================================== -FeaturesAPI_Translation::FeaturesAPI_Translation(const std::shared_ptr& theFeature) +FeaturesAPI_Translation::FeaturesAPI_Translation( + const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) { initialize(); } //================================================================================================== -FeaturesAPI_Translation::FeaturesAPI_Translation(const std::shared_ptr& theFeature, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theAxisObject, - const ModelHighAPI_Double& theDistance) +FeaturesAPI_Translation::FeaturesAPI_Translation( + const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theMainObjects, mymainObjects); + setAxisAndDistance(theAxisObject, theDistance); + } +} + +//================================================================================================== +FeaturesAPI_Translation::FeaturesAPI_Translation( + const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Double& theDx, + const ModelHighAPI_Double& theDy, + const ModelHighAPI_Double& theDz) : ModelHighAPI_Interface(theFeature) { if(initialize()) { - setMainObjects(theMainObjects); - setAxisObject(theAxisObject); - setDistance(theDistance); + fillAttribute(theMainObjects, mymainObjects); + setDimensions(theDx, theDy, theDz); + } +} + +//================================================================================================== +FeaturesAPI_Translation::FeaturesAPI_Translation( + const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Selection& theStartPoint, + const ModelHighAPI_Selection& theEndPoint) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theMainObjects, mymainObjects); + setPoints(theStartPoint, theEndPoint); } } @@ -36,7 +80,8 @@ FeaturesAPI_Translation::~FeaturesAPI_Translation() } //================================================================================================== -void FeaturesAPI_Translation::setMainObjects(const std::list& theMainObjects) +void FeaturesAPI_Translation::setMainObjects( + const std::list& theMainObjects) { fillAttribute(theMainObjects, mymainObjects); @@ -44,28 +89,143 @@ void FeaturesAPI_Translation::setMainObjects(const std::list& thePart, - const std::list& theMainObjects, - const ModelHighAPI_Selection& theAxisObject, - const ModelHighAPI_Double& theDistance) +void FeaturesAPI_Translation::setPoints(const ModelHighAPI_Selection& theStartPoint, + const ModelHighAPI_Selection& theEndPoint) { - std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Translation::ID()); - return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theAxisObject, theDistance)); + fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS(), mycreationMethod); + fillAttribute(theStartPoint, mystartPoint); + fillAttribute(theEndPoint, myendPoint); + + execute(); +} + +//================================================================================================== +void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeSelectionListPtr anAttrObjects = + aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); + theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects; + + std::string aCreationMethod = + aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value(); + + if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) { + AttributeSelectionPtr anAttrAxis = + aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID()); + AttributeDoublePtr anAttrDistance = + aBase->real(FeaturesPlugin_Translation::DISTANCE_ID()); + theDumper << ", axis = " << anAttrAxis << ", distance = " << anAttrDistance; + } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) { + AttributeDoublePtr anAttrDx = aBase->real(FeaturesPlugin_Translation::DX_ID()); + AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID()); + AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID()); + theDumper << ", vector = [" << anAttrDx << ", " << anAttrDy << ", " << anAttrDz << "]"; + } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) { + AttributeSelectionPtr anAttrStartPoint = + aBase->selection(FeaturesPlugin_Translation::START_POINT_ID()); + AttributeSelectionPtr anAttrEndPoint = + aBase->selection(FeaturesPlugin_Translation::END_POINT_ID()); + theDumper << ", startPoint = " << anAttrStartPoint << ", endPoint = " << anAttrEndPoint; + } + + if (!aBase->data()->version().empty()) + theDumper << ", keepSubResults = True"; + + theDumper << ")" << std::endl; +} + +//================================================================================================== +TranslationPtr addTranslation( + const std::shared_ptr& part, + const std::list& objects, + const std::pair& deprecated1, + const std::pair& deprecated2, + const std::pair& deprecated3, + const ModelHighAPI_Selection& axis, const ModelHighAPI_Double& distance, + const std::list& vector, + const ModelHighAPI_Selection& startPoint, const ModelHighAPI_Selection& endPoint, + const bool keepSubResults) +{ + std::shared_ptr aFeature = part->addFeature(FeaturesAPI_Translation::ID()); + if (!keepSubResults) + aFeature->data()->setVersion(""); + + static const int VEC_SIZE = 3; + + bool byAxis = axis.variantType() != ModelHighAPI_Selection::VT_Empty; + bool byVector = vector.size() == VEC_SIZE; + bool byPoints = startPoint.variantType() != ModelHighAPI_Selection::VT_Empty && + endPoint.variantType() != ModelHighAPI_Selection::VT_Empty; + + ModelHighAPI_Selection firstSel, secondSel; + ModelHighAPI_Double values[VEC_SIZE]; + if (byAxis) { + firstSel = axis; + values[0] = distance; + } + else if (byVector) { + std::list::const_iterator it = vector.begin(); + for (ModelHighAPI_Double* vIt = values; it != vector.end(); ++vIt, ++it) + *vIt = *it; + } + else if (byPoints) { + firstSel = startPoint; + secondSel = endPoint; + } + else { + byVector = deprecated1.first.variantType() == ModelHighAPI_Selection::VT_Empty; + if (byVector) { + values[0] = deprecated1.second; + values[1] = deprecated2.second; + values[2] = deprecated3.second; + } + else { + firstSel = deprecated1.first; + secondSel = deprecated2.first; + values[0] = deprecated2.second; + if (secondSel.variantType() == ModelHighAPI_Selection::VT_Empty) + byAxis = true; + else + byPoints = true; + } + } + + TranslationPtr aTranslation; + if (byAxis) + aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects, firstSel, values[0])); + else if (byVector) { + aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects, + values[0], values[1], values[2])); + } + else if (byPoints) + aTranslation.reset(new FeaturesAPI_Translation(aFeature, objects, firstSel, secondSel)); + + return aTranslation; }