#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
-
+//=================================================================================================
FeaturesAPI_NormalToFace::
FeaturesAPI_NormalToFace(const std::shared_ptr<ModelAPI_Feature>& theFeature)
: ModelHighAPI_Interface(theFeature)
initialize();
}
+//=================================================================================================
FeaturesAPI_NormalToFace::FeaturesAPI_NormalToFace(
const std::shared_ptr<ModelAPI_Feature>& theFeature,
const ModelHighAPI_Selection& theBaseFace,
}
}
+//=================================================================================================
FeaturesAPI_NormalToFace::FeaturesAPI_NormalToFace(
const std::shared_ptr<ModelAPI_Feature>& theFeature,
const ModelHighAPI_Selection& theBaseFace)
}
}
+//=================================================================================================
FeaturesAPI_NormalToFace::~FeaturesAPI_NormalToFace()
{
}
+//=================================================================================================
void FeaturesAPI_NormalToFace::dump(ModelHighAPI_Dumper& theDumper) const
{
FeaturePtr aBase = feature();
const std::string& aDocName = theDumper.name(aBase->document());
AttributeSelectionPtr anAttrObject;
- anAttrObject = aBase->selection(FeaturesPlugin_CreateNormalToFace::OBJECTS_LIST_ID());
+ anAttrObject = aBase->selection(FeaturesPlugin_CreateNormalToFace::FACE_SELECTED_ID());
theDumper << aBase << " = model.getNormal(" << aDocName << ", " << anAttrObject;
- if ( !aBase->string(FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID())->value().empty()){
+ if (!aBase->string(FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID())->value().empty()){
AttributeSelectionPtr anAttrVertex =
aBase->selection(FeaturesPlugin_CreateNormalToFace::VERTEX_SELECTED_ID());
}
//==================================================================================================
-
NormalPtr getNormal(const std::shared_ptr<ModelAPI_Document>& thePart,
- const ModelHighAPI_Selection& theBaseFace,
- const ModelHighAPI_Selection& theOptionnelPoint)
+ const ModelHighAPI_Selection& theBaseFace,
+ const ModelHighAPI_Selection& theOptionnelPoint)
{
FeaturePtr aFeature =
return aNormalToface;
}
+//=================================================================================================
NormalPtr getNormal(const std::shared_ptr<ModelAPI_Document>& thePart,
const ModelHighAPI_Selection& theBaseFace)
{
FEATURESAPI_EXPORT
virtual ~FeaturesAPI_NormalToFace();
- INTERFACE_3(FeaturesPlugin_CreateNormalToFace::ID(),
- faceSelected, FeaturesPlugin_CreateNormalToFace::OBJECTS_LIST_ID(),
+ INTERFACE_3(FeaturesPlugin_CreateNormalToFace::ID(),
+ faceSelected, FeaturesPlugin_CreateNormalToFace::FACE_SELECTED_ID(),
ModelAPI_AttributeSelection,
/** base face */,
vertexSelected, FeaturesPlugin_CreateNormalToFace::VERTEX_SELECTED_ID(),
TestFillet1D_Wire_3.py
TestFillet1D_Wire_4.py
TestFillet1D_Wire_5.py
+ TestNormalToFace.py
)
<source>
- <shape_selector id="main_objects"
+ <shape_selector id="face"
label="Face"
tooltip="Select a face"
shape_types="face"
<validator id="GeomValidators_ShapeType" parameters="wire,face"/>
</shape_selector>
<optionalbox id="vertex_option" title="Option">
- <shape_selector id="tool_objects"
+ <shape_selector id="vertex"
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>
#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 <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(FACE_SELECTED_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());
}
+//=================================================================================================
void FeaturesPlugin_CreateNormalToFace::execute()
{
-AttributeSelectionPtr aSelectionFace = selection(OBJECTS_LIST_ID());
-AttributeSelectionPtr aSelectionPoint = selection(VERTEX_SELECTED_ID());
-GeomShapePtr aShape;
-GeomShapePtr aShapePoint;
+ AttributeSelectionPtr aSelectionFace = selection(FACE_SELECTED_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 (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))
+ 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;
theDir = theNormal->line()->direction();
}
}
- aPnt->translate(theDir, 100 );
-
+ aPnt->translate(theDir, 100);
+
std::shared_ptr<GeomAPI_Edge> anEdge =
GeomAlgoAPI_EdgeBuilder::line(theNormal->firstPoint(),
aPnt);
}
}
+//=================================================================================================
void FeaturesPlugin_CreateNormalToFace::attributeChanged(const std::string& theID)
{
}
#include <GeomAPI_IPresentable.h>
#include <GeomAPI_IScreenParams.h>
-#include <GeomAlgoAPI_Box.h>
/// \class FeaturesPlugin_CreateNormalToFace
/// \ingroup Plugins
}
/// Attribute name for face selected.
- inline static const std::string& OBJECTS_LIST_ID()
+ inline static const std::string& FACE_SELECTED_ID()
{
- static const std::string MY_OBJECTS_LIST_ID("main_objects");
- return MY_OBJECTS_LIST_ID;
+ static const std::string MY_FACE_ID("face");
+ return MY_FACE_ID;
}
/// Attribute name for vertex selected.
inline static const std::string& VERTEX_SELECTED_ID()
{
- static const std::string MY_VERTEX_SELECTED_ID("tool_objects");
+ static const std::string MY_VERTEX_SELECTED_ID("vertex");
return MY_VERTEX_SELECTED_ID;
}
#include "FeaturesPlugin_NormalToFace.h"
#include <ModelAPI_AttributeSelection.h>
-#include <ModelAPI_AttributeDoubleArray.h>
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Data.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 <iomanip>
#include <sstream>
-#include <iostream>
+//=================================================================================================
FeaturesPlugin_NormalToFace::FeaturesPlugin_NormalToFace()
{
}
+//=================================================================================================
void FeaturesPlugin_NormalToFace::initAttributes()
{
// attribute for object selected
- data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(FACE_SELECTED_ID(), ModelAPI_AttributeSelection::typeId());
data()->addAttribute(VERTEX_SELECTED_ID(), ModelAPI_AttributeSelection::typeId());
// attributes for result message and values
data()->addAttribute(CREATENORMAL_ID(), ModelAPI_AttributeBoolean::typeId());
}
+//=================================================================================================
void FeaturesPlugin_NormalToFace::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();
+ AttributeSelectionPtr aSelectionFace = selection(FACE_SELECTED_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 (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))
+ 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;
theDir = theNormal->line()->direction();
}
}
- aPnt->translate(theDir, 100 );
-
+ aPnt->translate(theDir, 100);
+
std::shared_ptr<GeomAPI_Edge> anEdge =
- GeomAlgoAPI_EdgeBuilder::line(theNormal->firstPoint(),
- aPnt);
+ 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() )
+
+ if (boolean(CREATENORMAL_ID())->value()) {
+ if (!myCreateFeature.get())
createNormal();
updateNormal();
- }else{
- if( myCreateFeature.get() )
- {
+ } else {
+ if (myCreateFeature.get()) {
myCreateFeature->eraseResults();
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aDoc = aSession->activeDocument();
}
}
+//=================================================================================================
void FeaturesPlugin_NormalToFace::attributeChanged(const std::string& theID)
{
- if (theID == OBJECTS_LIST_ID()) {
- if( myCreateFeature.get() )
+ if (theID == FACE_SELECTED_ID()) {
+ if (myCreateFeature.get())
updateNormal();
}
}
void FeaturesPlugin_NormalToFace::createNormal()
{
SessionPtr aSession = ModelAPI_Session::get();
-
+
DocumentPtr aDoc = aSession->activeDocument();
if (aDoc.get()) {
}
}
+//=================================================================================================
void FeaturesPlugin_NormalToFace::updateNormal()
{
- myCreateFeature->selection(FeaturesPlugin_CreateNormalToFace::OBJECTS_LIST_ID())
- ->setValue( selection(OBJECTS_LIST_ID())->context() ,
- selection(OBJECTS_LIST_ID())->value() );
+ myCreateFeature->selection(FeaturesPlugin_CreateNormalToFace::FACE_SELECTED_ID())
+ ->setValue( selection(FACE_SELECTED_ID())->context() ,
+ selection(FACE_SELECTED_ID())->value() );
myCreateFeature->string(FeaturesPlugin_CreateNormalToFace::VERTEX_OPTION_ID())
->setValue( string(VERTEX_OPTION_ID())->value());
- if(!string(VERTEX_OPTION_ID())->value().empty())
- {
+ 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() );
#include <GeomAPI_IPresentable.h>
#include <GeomAPI_IScreenParams.h>
-#include <GeomAlgoAPI_Box.h>
/// \class FeaturesPlugin_NormalToFace
/// \ingroup Plugins
}
/// Attribute name for face selected.
- inline static const std::string& OBJECTS_LIST_ID()
+ inline static const std::string& FACE_SELECTED_ID()
{
- static const std::string MY_OBJECTS_LIST_ID("main_objects");
- return MY_OBJECTS_LIST_ID;
+ static const std::string MY_FACE_SELECTED_ID("face");
+ return MY_FACE_SELECTED_ID;
}
/// Attribute name for vertex selected.
inline static const std::string& VERTEX_SELECTED_ID()
{
- static const std::string MY_VERTEX_SELECTED_ID("tool_objects");
+ static const std::string MY_VERTEX_SELECTED_ID("vertex");
return MY_VERTEX_SELECTED_ID;
}
private:
- void createNormal();
+ void createNormal();
void updateNormal();
FeaturePtr myCreateFeature;
<source>
- <shape_selector id="main_objects"
+ <shape_selector id="face"
label="Face"
tooltip="Select a face"
shape_types="face"
<validator id="GeomValidators_ShapeType" parameters="wire,face"/>
</shape_selector>
<optionalbox id="vertex_option" title="Option">
- <shape_selector id="tool_objects"
+ <shape_selector id="vertex"
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>
<boolvalue id="createnormal" label="Create normal" default="false"/>
--- /dev/null
+# Copyright (C) 2014-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
+#
+
+"""
+ Unit test of ...
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+
+import os
+import math
+
+from ModelAPI import *
+from salome.shaper import model
+
+
+__updated__ = "2020-11-12"
+
+
+#=========================================================================
+# test creating normal to face
+#=========================================================================
+def test_Normal_to_face():
+
+ model.begin()
+ file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Brep","box1.brep")
+ partSet = model.moduleDocument()
+ Part_1 = model.addPart(partSet)
+ Part_1_doc = Part_1.document()
+ Import_1 = model.addImport(Part_1_doc,file_path)
+ model.do()
+ ### Create Normal
+ Normal_1 = model.getNormal(Part_1_doc, model.selection("FACE", "box1_1/Shape_6"))
+ model.end()
+
+ assert (len(Normal_1.results()) > 0)
+ assert(Normal_1.feature().error() == "")
+ anAxisResult = modelAPI_ResultConstruction(Normal_1.feature().firstResult())
+ assert (anAxisResult is not None)
+
+
+if __name__ == '__main__':
+
+ test_Normal_to_face()
+
+ #=========================================================================
+ # End of test
+ #=========================================================================
importResultFeature.rst
linearCopyFeature.rst
measurementFeature.rst
+ normalToFaceFeature.rst
pipeFeature.rst
placementFeature.rst
recoverFeature.rst
--- /dev/null
+
+ .. _tui_create_Normal_To_Face:
+
+Create Normal to a face
+=======================
+
+.. literalinclude:: examples/createNormalToFace.py
+ :linenos:
+ :language: python
+
+:download:`Download this script <examples/createNormalToFace.py>`
+
+ .. _tui_create_Normal_To_Face_At_Vertex:
+
+Create Normal to a face at vertex
+=================================
+
+.. literalinclude:: examples/createNormalToFaceAtVertex.py
+ :linenos:
+ :language: python
+
+:download:`Download this script <examples/createNormalToFaceAtVertex.py>`
\ No newline at end of file
--- /dev/null
+from salome.shaper import model
+import os
+
+model.begin()
+file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Brep","box1.brep")
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Import_1 = model.addImport(Part_1_doc,file_path)
+model.do()
+
+### Create BoundingBox
+Normal_1 = model.getNormal(Part_1_doc, model.selection("FACE", "box1_1/Shape_6"))
+model.do()
+model.end()
--- /dev/null
+
+from salome.shaper import model
+import os
+
+model.begin()
+file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Brep","box1.brep")
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Import_1 = model.addImport(Part_1_doc,file_path)
+model.do()
+
+### Create BoundingBox
+Normal_1 = model.getNormal(Part_1_doc, model.selection("FACE", "box1_1/Shape_6"),
+ model.selection("VERTEX", "[box1_1/Shape_2][box1_1/Shape_4][box1_1/Shape_6]"))
+model.do()
+model.end()
--- /dev/null
+.. |normalToFace.icon| image:: images/normal.png
+
+Normal to a face
+================
+
+The **Normal to a face** feature displays the normal to a face. A vertex can be specified to indicate the position of the normal else the center of face is used.
+
+the resulting normal can be created via a dedicated check-box **Create normal**. If this last is checked corresponding result and feature would be created.
+
+If the check-box **Create normal** isn't checked, **Apply** button does not generate any result and has the same effect as **Cancel** for this feature.
+
+To display the normal to a face in the active part:
+
+#. select in the Main Menu *Inspection - > Normal to a face* item or
+#. click |normalToFace.icon| **Normal to a face** button in the toolbar
+
+The property panel is shown below.
+
+.. figure:: images/normalToFacePropertyPanel.png
+ :align: center
+
+ Normal to a face
+
+
+Input fields:
+
+- **Face** contains face selected in 3D OCC viewer or object browser.
+- **Vertex** contains optionnal vertex selected in 3D OCC viewer or object browser.
+- **Create normal** check-box allow the creation of the normal (result and feature).
+
+**TUI Command**:
+
+.. py:function:: model.getNormal(Part, face)
+
+ :param part: The current part object.
+ :param object: A face in format *model.selection("FACE", face)*.
+ :return: Created normal to a face at center.
+
+Result
+""""""
+
+Result of **Normal to a face**.
+
+.. figure:: images/normalToFaceResult.png
+ :align: center
+
+ Normal to a face
+
+**See Also** a sample TUI Script of :ref:`tui_create_Normal_To_Face` operation.
+
+
+**TUI Command**:
+
+.. py:function:: model.getNormal(Part, face, vertex)
+
+ :param part: The current part object.
+ :param object: A face in format *model.selection("FACE", face)*.
+ :param object: A vertex in format *model.selection("VERTEX", vertex)*.
+ :return: Created normal to a face at vertex.
+
+Result
+""""""
+
+Result of **Normal to aface** where **Vertex** is selecteted.
+
+.. figure:: images/normalToFaceResultwithVertex.png
+ :align: center
+
+ Normal to a face at vertex
+
+**See Also** a sample TUI Script of :ref:`tui_create_Normal_To_Face_At_Vertex` operation.
\ No newline at end of file
</group>
<group id="Face">
<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">
+ icon="icons/Features/normale.png" helpfile="normalToFaceFeature.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">
+ icon="icons/Features/axis.png" helpfile="normalToFaceFeature.html" internal="1">
<source path="CreateNormalToFace_widget.xml"/>
</feature>
</group>