From: Jérôme Date: Wed, 21 Oct 2020 12:54:00 +0000 (+0200) Subject: Implementation of Point coordinates in menu Inspection X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=42e403a9aebff7ea038afe91e27fe81f0cb31f7a;p=modules%2Fshaper.git Implementation of Point coordinates in menu Inspection --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 5be23a997..28783fd69 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -100,6 +100,7 @@ MAYBE_UNUSED const static char* ATTR_TOOLTIP = FEATURE_TOOLTIP; MAYBE_UNUSED const static char* ATTR_ICON = FEATURE_ICON; MAYBE_UNUSED const static char* ATTR_LABEL = "label"; MAYBE_UNUSED const static char* ATTR_STYLE_SHEET = "styleSheet"; +MAYBE_UNUSED const static char* ATTR_IS_SELECTABLE = "isSelectable"; MAYBE_UNUSED const static char* ATTR_HTML_STYLE = "isHTML"; MAYBE_UNUSED const static char* ATTR_DEFAULT = "default"; MAYBE_UNUSED const static char* ATTR_INTERNAL = "internal"; diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index 0b8e3055c..280b95f2f 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -32,6 +32,7 @@ SET(PROJECT_HEADERS FeaturesAPI_Fillet.h FeaturesAPI_Intersection.h FeaturesAPI_Measurement.h + FeaturesAPI_PointCoordinates.h FeaturesAPI_MultiRotation.h FeaturesAPI_MultiTranslation.h FeaturesAPI_Partition.h @@ -65,6 +66,7 @@ SET(PROJECT_SOURCES FeaturesAPI_Fillet.cpp FeaturesAPI_Intersection.cpp FeaturesAPI_Measurement.cpp + FeaturesAPI_PointCoordinates.cpp FeaturesAPI_MultiRotation.cpp FeaturesAPI_MultiTranslation.cpp FeaturesAPI_Partition.cpp diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index b76fd2dc4..211fe3db4 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -211,6 +211,7 @@ %include "FeaturesAPI_Fillet.h" %include "FeaturesAPI_Intersection.h" %include "FeaturesAPI_Measurement.h" +%include "FeaturesAPI_PointCoordinates.h" %include "FeaturesAPI_MultiRotation.h" %include "FeaturesAPI_MultiTranslation.h" %include "FeaturesAPI_Partition.h" diff --git a/src/FeaturesAPI/FeaturesAPI_PointCoordinates.cpp b/src/FeaturesAPI/FeaturesAPI_PointCoordinates.cpp new file mode 100644 index 000000000..d8fdb6930 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_PointCoordinates.cpp @@ -0,0 +1,45 @@ +// Copyright (C) 2018-2020 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_PointCoordinates.h" + +#include +#include +#include +#include + +std::list pointCoordinates(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePoint) +{ + FeaturePtr aPointCoodFeat = thePart->addFeature(FeaturesPlugin_PointCoordinates::ID()); + + fillAttribute(thePoint, aPointCoodFeat + ->selection(FeaturesPlugin_PointCoordinates::POINT_SELECTED_ID())); + std::list res; + + // obtain result + AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast( + aPointCoodFeat->attribute(FeaturesPlugin_PointCoordinates::RESULT_VALUES_ID())); + + for ( int i : {0, 1, 2}) + res.push_back( aResult->value(i)); + + return res; +} + diff --git a/src/FeaturesAPI/FeaturesAPI_PointCoordinates.h b/src/FeaturesAPI/FeaturesAPI_PointCoordinates.h new file mode 100644 index 000000000..2c1abfa76 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_PointCoordinates.h @@ -0,0 +1,37 @@ +// Copyright (C) 2018-2020 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 +// + +#ifndef FeaturesAPI_PointCoordinates_H_ +#define FeaturesAPI_PointCoordinates_H_ + +#include "FeaturesAPI.h" + +#include +#include + +class ModelAPI_Document; +class ModelHighAPI_Selection; + +/// \ingroup CPPHighAPI +/// \brief ??? +FEATURESAPI_EXPORT +std::list pointCoordinates(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& thePoint); + +#endif // FeaturesAPI_PointCoordinates_H_ diff --git a/src/FeaturesAPI/FeaturesAPI_swig.h b/src/FeaturesAPI/FeaturesAPI_swig.h index 17ada7187..f338d877e 100644 --- a/src/FeaturesAPI/FeaturesAPI_swig.h +++ b/src/FeaturesAPI/FeaturesAPI_swig.h @@ -35,6 +35,7 @@ #include "FeaturesAPI_Fillet.h" #include "FeaturesAPI_Intersection.h" #include "FeaturesAPI_Measurement.h" + #include "FeaturesAPI_PointCoordinates.h" #include "FeaturesAPI_MultiRotation.h" #include "FeaturesAPI_MultiTranslation.h" #include "FeaturesAPI_Partition.h" diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index c93c66a17..d6fb6ae6c 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -19,6 +19,17 @@ INCLUDE(Common) INCLUDE(UnitTest) +INCLUDE(UseQtExt) + +# additional include directories +INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/Locale + ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin + ${QT_INCLUDES}) + +# additional preprocessor / compiler flags +ADD_DEFINITIONS(${QT_DEFINITIONS}) + SET(PROJECT_HEADERS FeaturesPlugin.h @@ -59,6 +70,7 @@ SET(PROJECT_HEADERS FeaturesPlugin_Fillet.h FeaturesPlugin_Fillet1D.h FeaturesPlugin_Measurement.h + FeaturesPlugin_PointCoordinates.h FeaturesPlugin_FusionFaces.h FeaturesPlugin_RemoveResults.h FeaturesPlugin_Chamfer.h @@ -106,6 +118,7 @@ SET(PROJECT_SOURCES FeaturesPlugin_Fillet.cpp FeaturesPlugin_Fillet1D.cpp FeaturesPlugin_Measurement.cpp + FeaturesPlugin_PointCoordinates.cpp FeaturesPlugin_FusionFaces.cpp FeaturesPlugin_RemoveResults.cpp FeaturesPlugin_Chamfer.cpp @@ -144,6 +157,7 @@ SET(XML_RESOURCES fillet_widget.xml fillet1d_widget.xml measurement_widget.xml + pointcoordinates_widget.xml fusion_faces_widget.xml chamfer_widget.xml copy_widget.xml @@ -166,6 +180,7 @@ INCLUDE_DIRECTORIES( ../GeomAPI ../GeomAlgoAPI ../GeomValidators + ../ModuleBase ../Events ../Config ${OpenCASCADE_INCLUDE_DIR} @@ -182,7 +197,11 @@ SET(PROJECT_LIBRARIES ) ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS) -ADD_LIBRARY(FeaturesPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES} ${TEXT_RESOURCES}) +ADD_LIBRARY(FeaturesPlugin MODULE + ${PROJECT_SOURCES} + ${PROJECT_HEADERS} + ${XML_RESOURCES} + ${TEXT_RESOURCES}) TARGET_LINK_LIBRARIES(FeaturesPlugin ${PROJECT_LIBRARIES}) INSTALL(TARGETS FeaturesPlugin DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES}) @@ -682,6 +701,4 @@ ADD_UNIT_TESTS(TestExtrusion.py TestFillet1D_Wire_3.py TestFillet1D_Wire_4.py TestFillet1D_Wire_5.py - Test19931.py - Test20027.py ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 0d49dfe08..9e97eb0ce 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -187,6 +188,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new FeaturesPlugin_Fillet1D); } else if (theFeatureID == FeaturesPlugin_Measurement::ID()) { return FeaturePtr(new FeaturesPlugin_Measurement); + } else if (theFeatureID == FeaturesPlugin_PointCoordinates::ID()) { + return FeaturePtr(new FeaturesPlugin_PointCoordinates); } else if (theFeatureID == FeaturesPlugin_RemoveResults::ID()) { return FeaturePtr(new FeaturesPlugin_RemoveResults); } else if (theFeatureID == FeaturesPlugin_Chamfer::ID()) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_PointCoordinates.cpp b/src/FeaturesPlugin/FeaturesPlugin_PointCoordinates.cpp new file mode 100644 index 000000000..eae9d3201 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_PointCoordinates.cpp @@ -0,0 +1,97 @@ +// Copyright (C) 2018-2020 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 "FeaturesPlugin_PointCoordinates.h" + +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include + +#include + +#include +#include + +FeaturesPlugin_PointCoordinates::FeaturesPlugin_PointCoordinates() +{ +} + +void FeaturesPlugin_PointCoordinates::initAttributes() +{ + // attribute for point selected + data()->addAttribute(POINT_SELECTED_ID(), ModelAPI_AttributeSelection::typeId()); + // attributes for result message and values + data()->addAttribute(X_COOD_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(Y_COOD_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(Z_COOD_ID(), ModelAPI_AttributeString::typeId()); + + data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId()); + + data()->realArray(RESULT_VALUES_ID())->setSize(3); + +} + +void FeaturesPlugin_PointCoordinates::execute() +{ +} + +void FeaturesPlugin_PointCoordinates::attributeChanged(const std::string& theID) +{ + if (theID == POINT_SELECTED_ID()) { + + AttributeSelectionPtr aSelection = selection(POINT_SELECTED_ID()); + AttributeDoubleArrayPtr aValues = + std::dynamic_pointer_cast(attribute(RESULT_VALUES_ID())); + std::stringstream streamx; + std::stringstream streamy; + std::stringstream streamz; + GeomShapePtr aShape; + GeomPointPtr aPoint; + if (aSelection && aSelection->isInitialized()) { + aShape = aSelection->value(); + if (!aShape && aSelection->context()) + aShape = aSelection->context()->shape(); + } + if (aShape){ + + aPoint = GeomAlgoAPI_PointBuilder::point(aShape); + streamx << std::setprecision(14) << aPoint->x(); + aValues->setValue(0, aPoint->x()); + streamy << std::setprecision(14) << aPoint->y(); + aValues->setValue(1, aPoint->y()); + streamz << std::setprecision(14) << aPoint->z(); + aValues->setValue(2, aPoint->z()); + } + + string(X_COOD_ID() )->setValue( "X = " + streamx.str() ); + string(Y_COOD_ID() )->setValue( "Y = " + streamy.str() ); + string(Z_COOD_ID() )->setValue( "Z = " + streamz.str() ); + } + +} + diff --git a/src/FeaturesPlugin/FeaturesPlugin_PointCoordinates.h b/src/FeaturesPlugin/FeaturesPlugin_PointCoordinates.h new file mode 100644 index 000000000..63ac47b1f --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_PointCoordinates.h @@ -0,0 +1,101 @@ +// Copyright (C) 2018-2020 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 +// + +#ifndef FeaturesPlugin_PointCoordinates_H_ +#define FeaturesPlugin_PointCoordinates_H_ + +#include "FeaturesPlugin.h" +#include + +#include +#include + +/// \class FeaturesPlugin_PointCoordinates +/// \ingroup Plugins +/// \brief Feature to view point coordinates. + +class FeaturesPlugin_PointCoordinates : public ModelAPI_Feature +{ +public: + inline static const std::string& ID() + { + static const std::string MY_ID("PointCoordinates"); + return MY_ID; + } + + /// \return the kind of a feature. + virtual const std::string& getKind() + { + return ID(); + } + + /// Attribute name for point selected. + inline static const std::string& POINT_SELECTED_ID() + { + static const std::string MY_POINT_SELECTED_ID("point_selected"); + return MY_POINT_SELECTED_ID; + } + + /// Attribute name for x coodinate. + inline static const std::string& X_COOD_ID() + { + static const std::string MY_X_COOOD_ID("xcoordinate"); + return MY_X_COOOD_ID; + } + + /// Attribute name for y coodinate. + inline static const std::string& Y_COOD_ID() + { + static const std::string MY_Y_COOOD_ID("ycoordinate"); + return MY_Y_COOOD_ID; + } + + /// Attribute name for z coodinate. + inline static const std::string& Z_COOD_ID() + { + static const std::string MY_Z_COOOD_ID("zcoordinate"); + return MY_Z_COOOD_ID; + } + + /// Attribute name for values of result. + inline static const std::string& RESULT_VALUES_ID() + { + static const std::string MY_RESULT_VALUES_ID("result_values"); + return MY_RESULT_VALUES_ID; + } + + /// Performs the algorithm and stores results it in the data structure. + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Called on change of any argument-attribute of this object + /// \param theID identifier of changed attribute + FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); + + /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true. + virtual bool isMacro() const { return true; } + + /// Use plugin manager for features creation + FeaturesPlugin_PointCoordinates(); + +}; + +#endif diff --git a/src/FeaturesPlugin/icons/point_coord.png b/src/FeaturesPlugin/icons/point_coord.png new file mode 100644 index 000000000..a3fe457be Binary files /dev/null and b/src/FeaturesPlugin/icons/point_coord.png differ diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 08c08b775..89b06e65e 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -134,7 +134,7 @@ + icon="icons/Features/fusion_faces.png" auto_preview="true" helpfile="FeaturesPlugin/fusionFacesFeature.html"> - + + + + + + diff --git a/src/FeaturesPlugin/pointcoordinates_widget.xml b/src/FeaturesPlugin/pointcoordinates_widget.xml new file mode 100644 index 000000000..7e5aa1151 --- /dev/null +++ b/src/FeaturesPlugin/pointcoordinates_widget.xml @@ -0,0 +1,13 @@ + + + + +