#include "FeaturesAPI_NormalToFace.h"
+#include <FeaturesPlugin_CreateNormalToFace.h>
#include <ModelHighAPI_Dumper.h>
#include <ModelHighAPI_Selection.h>
:ModelHighAPI_Interface(theFeature)
{
if (initialize()) {
- fillAttribute(theBaseFace, myfaceselected);
- fillAttribute(theOptionnelPoint, myvertexselected);
- feature()->string(FeaturesPlugin_NormalToFace::VERTEX_OPTION_ID())->setValue("true");
+ fillAttribute(theBaseFace, myfaceSelected);
+ fillAttribute(theOptionnelPoint, myvertexSelected);
+ feature()->string(FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID())->setValue("true");
execute();
}
}
:ModelHighAPI_Interface(theFeature)
{
if (initialize()) {
- fillAttribute(theBaseFace, myfaceselected);
- feature()->string(FeaturesPlugin_NormalToFace::VERTEX_OPTION_ID())->setValue("");
+ fillAttribute(theBaseFace, myfaceSelected);
+ feature()->string(FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID())->setValue("");
execute();
}
}
const std::string& aDocName = theDumper.name(aBase->document());
AttributeSelectionPtr anAttrObject;
- anAttrObject = aBase->selection(FeaturesPlugin_NormalToFace::OBJECTS_LIST_ID());
+ anAttrObject = aBase->selection(FeaturesPlugin_CreateNormalToFace::OBJECTS_LIST_ID());
theDumper << aBase << " = model.getNormal(" << aDocName << ", " << anAttrObject;
- if ( !aBase->string(FeaturesPlugin_NormalToFace::VERTEX_OPTION_ID())->value().empty()){
+ if ( !aBase->string(FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID())->value().empty()){
AttributeSelectionPtr anAttrVertex =
- aBase->selection(FeaturesPlugin_NormalToFace::VERTEX_SELECTED_ID());
+ aBase->selection(FeaturesPlugin_CreateNormalToFace::VERTEX_SELECTED_ID());
theDumper << ", " << anAttrVertex;
}
- //if (!aBase->data()->version().empty())
- // theDumper << ", keepSubResults = True";
-
theDumper << ")" << std::endl;
}
{
FeaturePtr aFeature =
- thePart->addFeature(FeaturesAPI_NormalToFace::ID());
+ thePart->addFeature(FeaturesPlugin_CreateNormalToFace::ID());
NormalPtr aNormalToface;
{
FeaturePtr aFeature =
- thePart->addFeature(FeaturesAPI_NormalToFace::ID());
+ thePart->addFeature(FeaturesPlugin_CreateNormalToFace::ID());
NormalPtr aNormalToface;
#include "FeaturesAPI.h"
-#include <FeaturesPlugin_NormalToFace.h>
+#include <FeaturesPlugin_CreateNormalToFace.h>
#include <ModelHighAPI_Interface.h>
#include <ModelHighAPI_Macro.h>
FEATURESAPI_EXPORT
virtual ~FeaturesAPI_NormalToFace();
- INTERFACE_3(FeaturesPlugin_NormalToFace::ID(),
- faceselected, FeaturesPlugin_NormalToFace::OBJECTS_LIST_ID(),
+ INTERFACE_3(FeaturesPlugin_CreateNormalToFace::ID(),
+ faceSelected, FeaturesPlugin_CreateNormalToFace::OBJECTS_LIST_ID(),
ModelAPI_AttributeSelection,
/** base face */,
- vertexselected, FeaturesPlugin_NormalToFace::VERTEX_SELECTED_ID(),
+ vertexSelected, FeaturesPlugin_CreateNormalToFace::VERTEX_SELECTED_ID(),
ModelAPI_AttributeSelection,
/** vetex option */,
- vertexoption, FeaturesPlugin_NormalToFace::VERTEX_OPTION_ID(),
+ vertexOption, FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID(),
ModelAPI_AttributeString,
/** option */)
FeaturesPlugin_Fillet1D.h
FeaturesPlugin_Measurement.h
FeaturesPlugin_NormalToFace.h
+ FeaturesPlugin_CreateNormalToFace.h
FeaturesPlugin_FusionFaces.h
FeaturesPlugin_RemoveResults.h
FeaturesPlugin_Chamfer.h
FeaturesPlugin_Fillet1D.cpp
FeaturesPlugin_Measurement.cpp
FeaturesPlugin_NormalToFace.cpp
+ FeaturesPlugin_CreateNormalToFace.cpp
FeaturesPlugin_FusionFaces.cpp
FeaturesPlugin_RemoveResults.cpp
FeaturesPlugin_Chamfer.cpp
fillet1d_widget.xml
measurement_widget.xml
NormalToFace_widget.xml
+ CreateNormalToFace_widget.xml
fusion_faces_widget.xml
chamfer_widget.xml
copy_widget.xml
--- /dev/null
+<source>
+ <shape_selector id="main_objects"
+ label="Face"
+ tooltip="Select a face"
+ shape_types="face"
+ default=""
+ geometrical_selection="true">
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="GeomValidators_ShapeType" parameters="wire,face"/>
+ </shape_selector>
+ <optionalbox id="vertex_option" title="Option">
+ <shape_selector id="tool_objects"
+ label="Vertex"
+ tooltip="Select a vertex"
+ shape_types="vertex"
+ default=""
+ geometrical_selection="true">
+ <validator id="PartSet_DifferentObjects"/>
+ <!--validator id="GeomValidators_ShapeType" parameters="vertex"/-->
+ </shape_selector>
+ </optionalbox>
+</source>
--- /dev/null
+// 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_CreateNormalToFace.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+#include <PrimitivesPlugin_Box.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Edge.h>
+#include <Config_PropManager.h>
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_NormalToFace.h>
+#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <iomanip>
+#include <sstream>
+#include <iostream>
+
+FeaturesPlugin_CreateNormalToFace::FeaturesPlugin_CreateNormalToFace()
+{
+}
+
+void FeaturesPlugin_CreateNormalToFace::initAttributes()
+{
+ // attribute for object selected
+ data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(VERTEX_SELECTED_ID(), ModelAPI_AttributeSelection::typeId());
+ // attributes for result message and values
+ data()->addAttribute(VERTEX_OPTION_ID(), ModelAPI_AttributeString::typeId());
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VERTEX_SELECTED_ID());
+
+}
+
+void FeaturesPlugin_CreateNormalToFace::execute()
+{
+AttributeSelectionPtr aSelectionFace = selection(OBJECTS_LIST_ID());
+AttributeSelectionPtr aSelectionPoint = selection(VERTEX_SELECTED_ID());
+
+GeomShapePtr aShape;
+GeomShapePtr aShapePoint;
+ if(!string(VERTEX_OPTION_ID())->value().empty())
+{
+ if (aSelectionPoint && aSelectionPoint->isInitialized()) {
+ aShapePoint = aSelectionPoint->value();
+ if (!aShapePoint && aSelectionPoint->context())
+ aShapePoint = aSelectionPoint->context()->shape();
+ }
+}
+
+if (aSelectionFace && aSelectionFace->isInitialized()) {
+ aShape = aSelectionFace->value();
+ if (!aShape && aSelectionFace->context())
+ aShape = aSelectionFace->context()->shape();
+}
+
+if (aShape){
+ std::string aError;
+ std::shared_ptr<GeomAPI_Edge> theNormal(new GeomAPI_Edge);
+ if( !GeomAlgoAPI_NormalToFace::normal(aShape,
+ aShapePoint,
+ theNormal,
+ aError))
+ setError("Error in bounding box calculation :" + aError);
+
+ GeomDirPtr theDir;
+ std::shared_ptr<GeomAPI_Pnt> aPnt = theNormal->lastPoint();
+ if (theNormal.get()) {
+ if (theNormal->isLine()) {
+ theDir = theNormal->line()->direction();
+ }
+ }
+ aPnt->translate(theDir, 100 );
+
+ std::shared_ptr<GeomAPI_Edge> anEdge =
+ GeomAlgoAPI_EdgeBuilder::line(theNormal->firstPoint(),
+ aPnt);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
+}
+
+void FeaturesPlugin_CreateNormalToFace::attributeChanged(const std::string& theID)
+{
+}
+
+
--- /dev/null
+// 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_CreateNormalToFace_H_
+#define FeaturesPlugin_CreateNormalToFace_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+
+#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_IScreenParams.h>
+#include <GeomAlgoAPI_Box.h>
+
+/// \class FeaturesPlugin_CreateNormalToFace
+/// \ingroup Plugins
+/// \brief Feature for construct normal to face
+
+class FeaturesPlugin_CreateNormalToFace : public ModelAPI_Feature
+{
+public:
+ inline static const std::string& ID()
+ {
+ static const std::string MY_ID("Normal");
+ return MY_ID;
+ }
+
+ /// \return the kind of a feature.
+ virtual const std::string& getKind()
+ {
+ return ID();
+ }
+
+ /// Attribute name for face selected.
+ inline static const std::string& OBJECTS_LIST_ID()
+ {
+ static const std::string MY_OBJECTS_LIST_ID("main_objects");
+ return MY_OBJECTS_LIST_ID;
+ }
+
+ /// Attribute name for vertex selected.
+ inline static const std::string& VERTEX_SELECTED_ID()
+ {
+ static const std::string MY_VERTEX_SELECTED_ID("tool_objects");
+ return MY_VERTEX_SELECTED_ID;
+ }
+
+ /// Attribute name of vertex option.
+ inline static const std::string& VERTEX_OPTION_ID()
+ {
+ static const std::string MY_VERTEX_OPTION_ID("vertex_option");
+ return MY_VERTEX_OPTION_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);
+
+ /// Use plugin manager for features creation
+ FeaturesPlugin_CreateNormalToFace();
+
+};
+
+#endif
#include <ModelAPI_Data.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+
+#include <GeomAlgoAPI_PointBuilder.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_Edge.h>
#include <Config_PropManager.h>
#include <GeomAPI_ShapeExplorer.h>
#include <GeomAPI_Ax1.h>
#include <GeomAPI_Lin.h>
+#include <GeomAPI_Dir.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <ModelAPI_ResultConstruction.h>
+#include <FeaturesPlugin_CreateNormalToFace.h>
+
#include <iomanip>
#include <sstream>
+#include <iostream>
FeaturesPlugin_NormalToFace::FeaturesPlugin_NormalToFace()
{
void FeaturesPlugin_NormalToFace::execute()
{
- AttributeSelectionPtr aSelectionFace = selection(OBJECTS_LIST_ID());
- AttributeSelectionPtr aSelectionPoint = selection(VERTEX_SELECTED_ID());
+AttributeSelectionPtr aSelectionFace = selection(OBJECTS_LIST_ID());
+AttributeSelectionPtr aSelectionPoint = selection(VERTEX_SELECTED_ID());
- GeomShapePtr aShape;
- GeomShapePtr aShapePoint;
- if(!string(VERTEX_OPTION_ID())->value().empty())
- {
- if (aSelectionPoint && aSelectionPoint->isInitialized()) {
- aShapePoint = aSelectionPoint->value();
- if (!aShapePoint && aSelectionPoint->context())
- aShapePoint = aSelectionPoint->context()->shape();
- }
+GeomShapePtr aShape;
+GeomShapePtr aShapePoint;
+ if(!string(VERTEX_OPTION_ID())->value().empty())
+{
+ if (aSelectionPoint && aSelectionPoint->isInitialized()) {
+ aShapePoint = aSelectionPoint->value();
+ if (!aShapePoint && aSelectionPoint->context())
+ aShapePoint = aSelectionPoint->context()->shape();
}
+}
- if (aSelectionFace && aSelectionFace->isInitialized()) {
- aShape = aSelectionFace->value();
- if (!aShape && aSelectionFace->context())
- aShape = aSelectionFace->context()->shape();
- }
+if (aSelectionFace && aSelectionFace->isInitialized()) {
+ aShape = aSelectionFace->value();
+ if (!aShape && aSelectionFace->context())
+ aShape = aSelectionFace->context()->shape();
+}
- if (aShape){
- std::string aError;
- std::shared_ptr<GeomAPI_Edge> theNormal(new GeomAPI_Edge);
- if( !GeomAlgoAPI_NormalToFace::normal(aShape,
- aShapePoint,
- theNormal,
- aError))
- setError("Error in bounding box calculation :" + aError);
-
- ResultBodyPtr aResultBody = document()->createBody(data());
- if( boolean(CREATENORMAL_ID())->value() )
- {
- eraseResults();
- std::shared_ptr<GeomAPI_Edge> anEdge =
- GeomAlgoAPI_EdgeBuilder::line(theNormal->firstPoint(),
- theNormal->lastPoint());
-
- ResultConstructionPtr aConstr = document()->createConstruction(data());
- aConstr->setInfinite(true);
- aConstr->setShape(anEdge);
- setResult(aConstr);
- }else
- {
- eraseResults();
- // Load the result
- aResultBody->store(theNormal);
- /*int aVertexIndex = 1;
- for (GeomAPI_ShapeExplorer anExp(theNormal, GeomAPI_Shape::VERTEX); anExp.more(); anExp.next()) {
- std::string aVertexName = "VertexFromNormal_" + std::to_string((long long)aVertexIndex);
- aResultBody->generated(anExp.current(), aVertexName);
- aVertexIndex++;
- }*/
- setResult(aResultBody);
+if (aShape){
+ std::string aError;
+ std::shared_ptr<GeomAPI_Edge> theNormal(new GeomAPI_Edge);
+ if( !GeomAlgoAPI_NormalToFace::normal(aShape,
+ aShapePoint,
+ theNormal,
+ aError))
+ setError("Error in bounding box calculation :" + aError);
+
+ GeomDirPtr theDir;
+ std::shared_ptr<GeomAPI_Pnt> aPnt = theNormal->lastPoint();
+ if (theNormal.get()) {
+ if (theNormal->isLine()) {
+ theDir = theNormal->line()->direction();
}
}
+ aPnt->translate(theDir, 100 );
+
+ std::shared_ptr<GeomAPI_Edge> anEdge =
+ GeomAlgoAPI_EdgeBuilder::line(theNormal->firstPoint(),
+ aPnt);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
+
+ if(boolean(CREATENORMAL_ID())->value())
+ {
+ if( !myCreateFeature.get() )
+ createNormal();
+ updateNormal();
+ }else{
+ if( myCreateFeature.get() )
+ {
+ myCreateFeature->eraseResults();
+ SessionPtr aSession = ModelAPI_Session::get();
+ DocumentPtr aDoc = aSession->activeDocument();
+ aDoc->removeFeature(myCreateFeature);
+ myCreateFeature.reset();
+ }
+ }
}
void FeaturesPlugin_NormalToFace::attributeChanged(const std::string& theID)
{
+ if (theID == OBJECTS_LIST_ID()) {
+ if( myCreateFeature.get() )
+ updateNormal();
+ }
}
+//=================================================================================================
+void FeaturesPlugin_NormalToFace::createNormal()
+{
+ SessionPtr aSession = ModelAPI_Session::get();
+
+ DocumentPtr aDoc = aSession->activeDocument();
+
+ if (aDoc.get()) {
+ myCreateFeature = aDoc->addFeature(FeaturesPlugin_CreateNormalToFace::ID());
+ }
+}
+void FeaturesPlugin_NormalToFace::updateNormal()
+{
+ myCreateFeature->selection(FeaturesPlugin_CreateNormalToFace::OBJECTS_LIST_ID())
+ ->setValue( selection(OBJECTS_LIST_ID())->context() ,
+ selection(OBJECTS_LIST_ID())->value() );
+
+ myCreateFeature->string(FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID())
+ ->setValue( string(VERTEX_OPTION_ID())->value());
+
+ if(!string(VERTEX_OPTION_ID())->value().empty())
+ {
+ myCreateFeature->selection(FeaturesPlugin_CreateNormalToFace::VERTEX_SELECTED_ID())
+ ->setValue( selection(VERTEX_SELECTED_ID())->context() ,
+ selection(VERTEX_SELECTED_ID())->value() );
+ }
+
+ myCreateFeature->execute();
+}
\ No newline at end of file
public:
inline static const std::string& ID()
{
- static const std::string MY_ID("Normal");
+ static const std::string MY_ID("NormalMacro");
return MY_ID;
}
/// \param theID identifier of changed attribute
FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+ /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
+ FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+
/// Use plugin manager for features creation
FeaturesPlugin_NormalToFace();
+ private:
+
+ void createNormal();
+ void updateNormal();
+ FeaturePtr myCreateFeature;
+
};
#endif
#include <FeaturesPlugin_Intersection.h>
#include <FeaturesPlugin_Measurement.h>
#include <FeaturesPlugin_NormalToFace.h>
+#include <FeaturesPlugin_CreateNormalToFace.h>
#include <FeaturesPlugin_MultiRotation.h>
#include <FeaturesPlugin_MultiTranslation.h>
#include <FeaturesPlugin_Partition.h>
} else if (theFeatureID == FeaturesPlugin_Measurement::ID()) {
return FeaturePtr(new FeaturesPlugin_Measurement);
} else if (theFeatureID == FeaturesPlugin_NormalToFace::ID()) {
- return FeaturePtr(new FeaturesPlugin_NormalToFace);
+ return FeaturePtr(new FeaturesPlugin_NormalToFace);
+ } else if (theFeatureID == FeaturesPlugin_CreateNormalToFace::ID()) {
+ return FeaturePtr(new FeaturesPlugin_CreateNormalToFace);
} else if (theFeatureID == FeaturesPlugin_RemoveResults::ID()) {
return FeaturePtr(new FeaturesPlugin_RemoveResults);
} else if (theFeatureID == FeaturesPlugin_Chamfer::ID()) {
</feature>
</group>
<group id="Face">
- <feature id="Normal" title="Normal to a face" tooltip="Calculate the normal to a face" auto_preview="true"
+ <feature id="NormalMacro" title="Normal to a face" tooltip="Calculate the normal to a face" auto_preview="true"
icon="icons/Features/normale.png" helpfile="measurementFeature.html">
<source path="NormalToFace_widget.xml"/>
</feature>
+ <feature id="Normal" title="Normal to a face" tooltip="Calculate the normal to a face" auto_preview="true"
+ icon="icons/Features/axis.png" helpfile="measurementFeature.html" internal="1">
+ <source path="CreateNormalToFace_widget.xml"/>
+ </feature>
</group>
</workbench>
</plugin>