Now intersection feature contains only one "Objects" field ("Tools" field was removed)
Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection(), 100, 0)
Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], model.selection("EDGE", "PartSet/OX"), 90)
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Rotation_1_1")], [model.selection("SOLID", "Extrusion_2_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Rotation_1_1"), model.selection("SOLID", "Extrusion_2_1")])
Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
SketchLine_1 = Sketch_3.addLine(7.903534676574237, 7.903534676574236, -7.903534676574236, 7.903534676574236)
//==================================================================================================
FeaturesAPI_Intersection::FeaturesAPI_Intersection(
const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::list<ModelHighAPI_Selection>& theObjects,
- const std::list<ModelHighAPI_Selection>& theTools)
+ const std::list<ModelHighAPI_Selection>& theObjects)
: ModelHighAPI_Interface(theFeature)
{
if(initialize()) {
fillAttribute(theObjects, myobjects);
- fillAttribute(theTools, mytools);
execute();
}
execute();
}
-//==================================================================================================
-void FeaturesAPI_Intersection::setTools(const std::list<ModelHighAPI_Selection>& theTools)
-{
- fillAttribute(theTools, mytools);
-
- execute();
-}
-
//==================================================================================================
void FeaturesAPI_Intersection::dump(ModelHighAPI_Dumper& theDumper) const
{
AttributeSelectionListPtr anAttrObjects =
aBase->selectionList(FeaturesPlugin_Intersection::OBJECT_LIST_ID());
- AttributeSelectionListPtr anAttrTools =
- aBase->selectionList(FeaturesPlugin_Intersection::TOOL_LIST_ID());
theDumper << aBase << " = model.addIntersection(" << aDocName << ", "
- << anAttrObjects << ", " << anAttrTools << ")" << std::endl;
+ << anAttrObjects << ")" << std::endl;
}
//==================================================================================================
IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
- const std::list<ModelHighAPI_Selection>& theObjects,
- const std::list<ModelHighAPI_Selection>& theTools)
+ const std::list<ModelHighAPI_Selection>& theObjects)
{
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Intersection::ID());
- return IntersectionPtr(new FeaturesAPI_Intersection(aFeature, theObjects, theTools));
+ return IntersectionPtr(new FeaturesAPI_Intersection(aFeature, theObjects));
}
/// Constructor with values.
FEATURESAPI_EXPORT
explicit FeaturesAPI_Intersection(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::list<ModelHighAPI_Selection>& theObjects,
- const std::list<ModelHighAPI_Selection>& theTools);
+ const std::list<ModelHighAPI_Selection>& theObjects);
/// Destructor.
FEATURESAPI_EXPORT
virtual ~FeaturesAPI_Intersection();
- INTERFACE_2(FeaturesPlugin_Intersection::ID(),
+ INTERFACE_1(FeaturesPlugin_Intersection::ID(),
objects, FeaturesPlugin_Intersection::OBJECT_LIST_ID(),
- ModelAPI_AttributeSelectionList, /** Objects */,
- tools, FeaturesPlugin_Intersection::TOOL_LIST_ID(),
- ModelAPI_AttributeSelectionList, /** Tools */)
+ ModelAPI_AttributeSelectionList, /** Objects */)
/// Modify objects attribute of the feature.
FEATURESAPI_EXPORT
void setObjects(const std::list<ModelHighAPI_Selection>& theObjects);
- /// Modify tools attribute of the feature.
- FEATURESAPI_EXPORT
- void setTools(const std::list<ModelHighAPI_Selection>& theTools);
-
/// Dump wrapped feature
FEATURESAPI_EXPORT
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
/// \brief Create Intersection feature.
FEATURESAPI_EXPORT
IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
- const std::list<ModelHighAPI_Selection>& theObjects,
- const std::list<ModelHighAPI_Selection>& theTools);
+ const std::list<ModelHighAPI_Selection>& theObjects);
#endif // FeaturesAPI_Intersection_H_
//=================================================================================================
void FeaturesPlugin_Intersection::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_Intersection::OBJECT_LIST_ID(),
- ModelAPI_AttributeSelectionList::typeId());
- data()->addAttribute(FeaturesPlugin_Intersection::TOOL_LIST_ID(),
+ data()->addAttribute(OBJECT_LIST_ID(),
ModelAPI_AttributeSelectionList::typeId());
}
//=================================================================================================
void FeaturesPlugin_Intersection::execute()
{
- ListOfShape anObjects, aTools;
+ ListOfShape anObjects;
// Getting objects.
- AttributeSelectionListPtr anObjectsSelList =
- selectionList(FeaturesPlugin_Intersection::OBJECT_LIST_ID());
+ AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECT_LIST_ID());
for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
anObjectsSelList->value(anObjectsIndex);
anObjects.push_back(anObject);
}
- // Getting tools.
- AttributeSelectionListPtr aToolsSelList =
- selectionList(FeaturesPlugin_Intersection::TOOL_LIST_ID());
- for (int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) {
- std::shared_ptr<ModelAPI_AttributeSelection> aToolAttr = aToolsSelList->value(aToolsIndex);
- std::shared_ptr<GeomAPI_Shape> aTool = aToolAttr->value();
- if (!aTool.get()) {
- return;
- }
- aTools.push_back(aTool);
- }
-
- if(anObjects.empty() || aTools.empty()) {
+ if(anObjects.empty()) {
setError("Error: Objects or tools are empty.");
return;
}
int aResultIndex = 0;
- // Create result for each object.
- for (ListOfShape::iterator
- anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
- std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
- ListOfShape aListWithObject; aListWithObject.push_back(anObject);
- GeomAlgoAPI_Intersection anIntersectionAlgo(aListWithObject, aTools);
-
- // Checking that the algorithm worked properly.
- if (!anIntersectionAlgo.isDone()) {
- static const std::string aFeatureError = "Error: Intersection algorithm failed.";
- setError(aFeatureError);
- return;
- }
- if (anIntersectionAlgo.shape()->isNull()) {
- static const std::string aShapeError = "Error: Resulting shape is Null.";
- setError(aShapeError);
- return;
- }
- if (!anIntersectionAlgo.isValid()) {
- std::string aFeatureError = "Error: Resulting shape is not valid.";
- setError(aFeatureError);
- return;
- }
+ // Create result.
+ GeomAlgoAPI_Intersection anIntersectionAlgo(anObjects);
- std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
- loadNamingDS(aResultBody, anObject, aTools, anIntersectionAlgo);
- setResult(aResultBody, aResultIndex);
- aResultIndex++;
+ // Checking that the algorithm worked properly.
+ if (!anIntersectionAlgo.isDone()) {
+ static const std::string aFeatureError = "Error: Intersection algorithm failed.";
+ setError(aFeatureError);
+ return;
}
+ if (anIntersectionAlgo.shape()->isNull()) {
+ static const std::string aShapeError = "Error: Resulting shape is Null.";
+ setError(aShapeError);
+ return;
+ }
+ if (!anIntersectionAlgo.isValid()) {
+ std::string aFeatureError = "Error: Resulting shape is not valid.";
+ setError(aFeatureError);
+ return;
+ }
+
+ std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+ loadNamingDS(aResultBody, anObjects, anIntersectionAlgo);
+ setResult(aResultBody, aResultIndex);
+ aResultIndex++;
+
// remove the rest results if there were produced in the previous pass
removeResults(aResultIndex);
//=================================================================================================
void FeaturesPlugin_Intersection::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- const std::shared_ptr<GeomAPI_Shape> theBaseShape,
- const ListOfShape& theTools,
+ const ListOfShape& theObjects,
GeomAlgoAPI_MakeShape& theMakeShape)
{
std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape.shape();
- theResultBody->storeModified(theBaseShape, aResultShape);
-
- const int aDeletedVertexTag = 1;
- const int aDeletedEdgeTag = 2;
- const int aDeletedFaceTag = 3;
-
- theResultBody->loadDeletedShapes(&theMakeShape,
- theBaseShape,
- GeomAPI_Shape::VERTEX,
- aDeletedVertexTag);
- theResultBody->loadDeletedShapes(&theMakeShape,
- theBaseShape,
- GeomAPI_Shape::EDGE,
- aDeletedEdgeTag);
- theResultBody->loadDeletedShapes(&theMakeShape,
- theBaseShape,
- GeomAPI_Shape::FACE,
- aDeletedFaceTag);
-
- ListOfShape aShapes = theTools;
- aShapes.push_back(theBaseShape);
+ theResultBody->storeModified(theObjects.front(), aResultShape);
+
GeomAPI_DataMapOfShapeShape aShapesMap; // Map to store {result_shape, original_shape}
const int aShapeTypesNb = 2;
const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] =
{GeomAPI_Shape::VERTEX, GeomAPI_Shape::EDGE};
- for(ListOfShape::const_iterator anIt = aShapes.cbegin(); anIt != aShapes.cend(); ++anIt) {
+ for (ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) {
const GeomShapePtr aShape = *anIt;
for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
for(GeomAPI_ShapeExplorer anOrigShapeExp(aShape, aShapeTypes[anIndex]);
return MY_OBJECT_LIST_ID;
}
- /// Attribute name of tools.
- inline static const std::string& TOOL_LIST_ID()
- {
- static const std::string MY_TOOL_LIST_ID("tool_objects");
- return MY_TOOL_LIST_ID;
- }
-
/// Returns the kind of a feature.
FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
{
private:
/// Load Naming data structure of the feature to the document.
void loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- const std::shared_ptr<GeomAPI_Shape> theBaseShape,
- const ListOfShape& theTools,
+ const ListOfShape& theObjects,
GeomAlgoAPI_MakeShape& theMakeShape);
};
new FeaturesPlugin_ValidatorBooleanArguments);
aFactory->registerValidator("FeaturesPlugin_ValidatorBooleanSmashSelection",
new FeaturesPlugin_ValidatorBooleanSmashSelection);
+ aFactory->registerValidator("FeaturesPlugin_IntersectionSelection",
+ new FeaturesPlugin_IntersectionSelection);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
return true;
}
+
+//==================================================================================================
+bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ if (!theAttribute.get()) {
+ theError = "Error: empty selection.";
+ return false;
+ }
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeSelectionListPtr anAttrSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+ if (!anAttrSelection.get()) {
+ theError = "Error: empty attribute selection.";
+ return false;
+ }
+ ResultPtr aContext = anAttrSelection->context();
+ if (!aContext.get()) {
+ theError = "Error: empty selection context.";
+ return false;
+ }
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+ if (!aFeature.get()) {
+ theError = "Error: empty feature.";
+ return false;
+ }
+ std::string aFeatureKind = aFeature->getKind();
+ if (aFeatureKind == "Sketch" ||
+ aFeatureKind == "Plane" ||
+ aFeatureKind == "Axis") {
+ theError = "Error: %1 shape is not allowed for selection.";
+ theError.arg(aFeatureKind);
+ return false;
+ }
+ std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+ GeomShapePtr aContextShape = aContext->shape();
+ if (!aShape.get()) {
+ aShape = aContextShape;
+ }
+ if (!aShape.get()) {
+ theError = "Error: empty shape.";
+ return false;
+ }
+ if (!aShape->isEqual(aContextShape)) {
+ theError = "Error: Local selection not allowed.";
+ return false;
+ }
+
+ int aShapeType = aShape->shapeType();
+ // Allow to select edges, faces and solids.
+ if (aShapeType != GeomAPI_Shape::EDGE &&
+ aShapeType != GeomAPI_Shape::FACE &&
+ aShapeType != GeomAPI_Shape::SOLID &&
+ aShapeType != GeomAPI_Shape::COMPSOLID &&
+ aShapeType != GeomAPI_Shape::COMPOUND) {
+ theError = "Error: selected shape has the wrong type.";
+ return false;
+ }
+ }
+
+ return true;
+}
Events_InfoMessage& theError) const;
};
+/// \class FeaturesPlugin_IntersectionSelection
+/// \ingroup Validators
+/// \brief Verifies the selected object for intersection feature
+class FeaturesPlugin_IntersectionSelection: public ModelAPI_AttributeValidator
+{
+public:
+ //! \return True if the attribute is valid.
+ //! \param[in] theAttribute the checked attribute.
+ //! \param[in] theArguments arguments of the attribute.
+ //! \param[out] theError error message.
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
#endif
Recover_1 = model.addRecover(Part_1_doc, Partition_1, [Revolution_1.result()])
Plane_5 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/Axis_4"), model.selection("VERTEX", "PartSet/Point_2"), True)
Face_1 = model.addFace(Part_1_doc, [model.selection("EDGE", "Sketch_1/Edge-SketchArc_2_2"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_4"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_5"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_6"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_7"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_8"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_2")])
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Recover_1_1")], [model.selection("FACE", "Face_1_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Recover_1_1"), model.selection("FACE", "Face_1_1")])
Group_1 = model.addGroup(Part_1_doc, [model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_2_1"), model.selection("VERTEX", "Intersection_1_1/Generated_Vertex_2"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_6_1"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_4_1"), model.selection("VERTEX", "Intersection_1_1/Generated_Vertex_3"), model.selection("VERTEX", "Intersection_1_1/Generated_Vertex_1"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_1_1"), model.selection("VERTEX", "Intersection_1_1/Generated_Vertex_4"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_3_1"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_7_1"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_5_1")])
Group_2 = model.addGroup(Part_1_doc, [model.selection("EDGE", "Intersection_1_1_7"), model.selection("EDGE", "Intersection_1_1_6"), model.selection("EDGE", "Intersection_1_1_3"), model.selection("EDGE", "Intersection_1_1_11"), model.selection("EDGE", "Intersection_1_1_5"), model.selection("EDGE", "Intersection_1_1_1"), model.selection("EDGE", "Intersection_1_1_4"), model.selection("EDGE", "Intersection_1_1_2"), model.selection("EDGE", "Intersection_1_1_10"), model.selection("EDGE", "Intersection_1_1_9"), model.selection("EDGE", "Intersection_1_1_8")])
model.end()
SketchConstraintVertical_4 = Sketch_2.setVertical(SketchLine_8.result())
model.do()
Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_5f-SketchLine_6f-SketchLine_7f-SketchLine_8f")], model.selection(), 10, 110)
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_2_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1"), model.selection("SOLID", "Extrusion_2_1")])
Rotation_1 = model.addRotation(Part_1_doc, [model.selection("COMPOUND", "Intersection_1_1")], model.selection("EDGE", "PartSet/OZ"), 45)
model.end()
anIntersectionFt = aPart.addFeature("Intersection")
assert (anIntersectionFt.getKind() == "Intersection")
anIntersectionFt.selectionList("main_objects").append(anExtrusionResult1, None)
-anIntersectionFt.selectionList("tool_objects").append(anExtrusionResult2, None)
+anIntersectionFt.selectionList("main_objects").append(anExtrusionResult2, None)
anIntersectionFt.execute()
aSession.finishOperation()
use_choice="false"
concealment="true">
<validator id="PartSet_DifferentObjects"/>
- <validator id="GeomValidators_IntersectionSelection"/>
- </multi_selector>
- <multi_selector id="tool_objects"
- label="Tool objects"
- icon="icons/Features/cut_tool.png"
- tooltip="Select tools(compounds, compsolids, solids, shells, faces or edges)"
- type_choice="edges faces shells solids compsolids compounds"
- use_choice="false"
- concealment="true">
- <validator id="PartSet_DifferentObjects"/>
- <validator id="GeomValidators_IntersectionSelection"/>
+ <validator id="FeaturesPlugin_IntersectionSelection"/>
</multi_selector>
</source>
#include "GeomAlgoAPI_Intersection.h"
#include <GeomAlgoAPI_DFLoader.h>
-#include <GeomAlgoAPI_ShapeTools.h>
-#include <BRepAlgoAPI_Section.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopoDS_Builder.hxx>
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BOPAlgo_Section.hxx>
-//=================================================================================================
-GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
- const ListOfShape& theTools)
+//==================================================================================================
+GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects)
{
- build(theObjects, theTools);
+ build(theObjects);
}
-//=================================================================================================
-void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
- const ListOfShape& theTools)
+//==================================================================================================
+void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects)
{
- if (theObjects.empty() || theTools.empty()) {
+ if (theObjects.empty()) {
return;
}
// Creating partition operation.
- BRepAlgoAPI_Section* anOperation = new BRepAlgoAPI_Section;
+ BOPAlgo_Section* anOperation = new BOPAlgo_Section;
this->setImpl(anOperation);
- this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
- TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
+ this->setBuilderType(OCCT_BOPAlgo_Builder);
// Getting objects.
TopTools_ListOfShape anObjects;
anObjects.Append(aShape);
}
}
- anOperation->SetArguments(anObjects);
- // Getting tools.
- TopTools_ListOfShape aTools;
- for (ListOfShape::const_iterator
- aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
- const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
- if(!aShape.IsNull()) {
- aTools.Append(aShape);
- }
- }
- anOperation->SetTools(aTools);
+ BOPAlgo_PaveFiller aDSFiller;
+ aDSFiller.SetArguments(anObjects);
+
+ aDSFiller.SetRunParallel(false);
+ aDSFiller.SetNonDestructive(false);
+ aDSFiller.SetGlue(BOPAlgo_GlueOff);
+
// optimization for the issue #2399
- anOperation->Approximation(Standard_True);
- anOperation->ComputePCurveOn1(Standard_True);
- anOperation->ComputePCurveOn2(Standard_True);
- // Building and getting result.
- anOperation->Build();
- if(!anOperation->IsDone()) {
+ BOPAlgo_SectionAttribute theSecAttr(Standard_True,
+ Standard_True,
+ Standard_True);
+ aDSFiller.SetSectionAttribute(theSecAttr);
+
+ aDSFiller.Perform();
+ if (aDSFiller.HasErrors()) {
+ return;
+ }
+
+ anOperation->SetArguments(anObjects);
+ anOperation->SetRunParallel(false);
+ anOperation->SetCheckInverted(true);
+
+ anOperation->PerformWithFiller(aDSFiller);
+ if(anOperation->HasErrors()) {
return;
}
TopoDS_Shape aResult = anOperation->Shape();
/// \brief Constructor.
/// \param[in] theObjects list of objects.
/// \param[in] theTools list of tools.
- GEOMALGOAPI_EXPORT GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
- const ListOfShape& theTools);
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Intersection(const ListOfShape& theObjects);
private:
/// Builds resulting shape.
- void build(const ListOfShape& theObjects,
- const ListOfShape& theTools);
+ void build(const ListOfShape& theObjects);
};
#endif
GeomValidators_Tools.h
GeomValidators_ZeroOffset.h
GeomValidators_Different.h
- GeomValidators_IntersectionSelection.h
GeomValidators_MinObjectsSelected.h
GeomValidators_ValueOrder.h
GeomValidators_Intersected.h
GeomValidators_Tools.cpp
GeomValidators_ZeroOffset.cpp
GeomValidators_Different.cpp
- GeomValidators_IntersectionSelection.cpp
GeomValidators_MinObjectsSelected.cpp
GeomValidators_ValueOrder.cpp
GeomValidators_Intersected.cpp
+++ /dev/null
-// Copyright (C) 2014-2017 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<mailto:webmaster.salome@opencascade.com>
-//
-
-#include "GeomValidators_IntersectionSelection.h"
-
-#include <GeomAPI_Shape.h>
-
-#include <Events_InfoMessage.h>
-
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_Feature.h>
-
-bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- Events_InfoMessage& theError) const
-{
- if(!theAttribute.get()) {
- theError = "Error: empty selection.";
- return false;
- }
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
- AttributeSelectionListPtr anAttrSelectionList =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
- AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
- if(!anAttrSelection.get()) {
- theError = "Error: empty attribute selection.";
- return false;
- }
- ResultPtr aContext = anAttrSelection->context();
- if(!aContext.get()) {
- theError = "Error: empty selection context.";
- return false;
- }
- FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
- if(!aFeature.get()) {
- theError = "Error: empty feature.";
- return false;
- }
- std::string aFeatureKind = aFeature->getKind();
- if(aFeatureKind == "Sketch" ||
- aFeatureKind == "Plane" ||
- aFeatureKind == "Axis") {
- theError = "Error: %1 shape is not allowed for selection.";
- theError.arg(aFeatureKind);
- return false;
- }
- std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
- GeomShapePtr aContextShape = aContext->shape();
- if(!aShape.get()) {
- aShape = aContextShape;
- }
- if(!aShape.get()) {
- theError = "Error: empty shape.";
- return false;
- }
- if(!aShape->isEqual(aContextShape)) {
- theError = "Error: Local selection not allowed.";
- return false;
- }
-
- int aShapeType = aShape->shapeType();
- // Allow to select edges, faces and solids.
- if(aShapeType != GeomAPI_Shape::EDGE &&
- aShapeType != GeomAPI_Shape::FACE &&
- aShapeType != GeomAPI_Shape::SOLID &&
- aShapeType != GeomAPI_Shape::COMPSOLID &&
- aShapeType != GeomAPI_Shape::COMPOUND) {
- theError = "Error: selected shape has the wrong type.";
- return false;
- }
- }
-
- return true;
-}
+++ /dev/null
-// Copyright (C) 2014-2017 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<mailto:webmaster.salome@opencascade.com>
-//
-
-#ifndef GeomValidators_IntersectionSelection_H
-#define GeomValidators_IntersectionSelection_H
-
-#include <GeomValidators.h>
-
-#include <ModelAPI_AttributeValidator.h>
-#include <ModelAPI_Attribute.h>
-
-/// \class GeomValidators_IntersectionSelection
-/// \ingroup Validators
-/// \brief Validates selection for intersection operation.
-class GeomValidators_IntersectionSelection: public ModelAPI_AttributeValidator
-{
-public:
- /// \return True if the attribute is valid. It checks whether the selection
- /// is acceptable for intersection operation.
- /// \param[in] theAttribute an attribute to check.
- /// \param[in] theArguments a filter parameters.
- /// \param[out] theError error message.
- GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- Events_InfoMessage& theError) const;
-};
-
-#endif
#include <GeomValidators_PartitionArguments.h>
#include <GeomValidators_ShapeType.h>
#include <GeomValidators_ZeroOffset.h>
-#include <GeomValidators_IntersectionSelection.h>
#include <GeomValidators_FeatureKind.h>
#include <GeomValidators_MinObjectsSelected.h>
#include <GeomValidators_Intersected.h>
new GeomValidators_PartitionArguments);
aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset);
- aFactory->registerValidator("GeomValidators_IntersectionSelection",
- new GeomValidators_IntersectionSelection);
aFactory->registerValidator("GeomValidators_FeatureKind", new GeomValidators_FeatureKind);
aFactory->registerValidator("GeomValidators_MinObjectsSelected",
new GeomValidators_MinObjectsSelected);
SketchConstraintDistance_4 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_6.result(), 70, True)
model.do()
Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_3r-SketchLine_4r-SketchLine_5r-SketchLine_6r")])
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1")], [model.selection("FACE", "Face_1_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1"), model.selection("FACE", "Face_1_1")])
# set different edges used for intersection and check reference data: number of intersection points and their coordinates
REF_DATA = [("Sketch_1/Edge-SketchArc_1_2", 1, [[30, 0]]),
Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_1f-SketchLine_2f")], model.selection(), 25, 25)
Filling_1 = model.addFilling(Part_1_doc, [model.selection("EDGE", "Extrusion_1_1/Generated_Face_1&Extrusion_1_1/From_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/To_Face_1")])
Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_1f-SketchLine_2f")])
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1")], [model.selection("FACE", "Face_1_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1"), model.selection("FACE", "Face_1_1")])
Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
SketchLine_4 = Sketch_2.addLine(-34.11217447219568, 40, 20, -37.28019411294778)
SketchLine_5 = Sketch_2.addLine(20, -37.28019411294778, 20, 40)
# Translation 27
Translation_27_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_2_1")], [model.selection("SOLID", "Translation_1_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Translation_1_1")])
Translation_27 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_1_1")], model.selection("EDGE", "PartSet/OX"), 15)
# Translation 28
Translation_28_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_2 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_4_1")], [model.selection("SOLID", "Translation_3_1")])
+Intersection_2 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_4_1"), model.selection("SOLID", "Translation_3_1")])
Translation_28 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_2_1")], model.selection("EDGE", "PartSet/OX"), 0)
# Translation 29
Translation_29_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_5_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_3 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_6_1")], [model.selection("SOLID", "Translation_5_1")])
+Intersection_3 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_6_1"), model.selection("SOLID", "Translation_5_1")])
Translation_29 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_3_1")], model.selection("EDGE", "PartSet/OX"), -15)
# Translation 30
Translation_30_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_7_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_4 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_8_1")], [model.selection("SOLID", "Translation_7_1")])
+Intersection_4 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_8_1"), model.selection("SOLID", "Translation_7_1")])
Translation_30 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_4_1")], model.selection("EDGE", "InvalidName"), -15)
# Translation 31
Translation_31_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_9_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_5 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_10_1")], [model.selection("SOLID", "Translation_9_1")])
+Intersection_5 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_10_1"), model.selection("SOLID", "Translation_9_1")])
Translation_31 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_5_1")], model.selection("EDGE", "PartSet/OY"), "d")
# Translation 32
Translation_32_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_11_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_6 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_12_1")], [model.selection("SOLID", "Translation_11_1")])
+Intersection_6 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_12_1"), model.selection("SOLID", "Translation_11_1")])
Translation_32 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_6_1")], model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), 15)
# Translation 33
Translation_33_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_13_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_7 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_14_1")], [model.selection("SOLID", "Translation_13_1")])
+Intersection_7 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_14_1"), model.selection("SOLID", "Translation_13_1")])
Translation_33 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_7_1")], model.selection("EDGE", "Edge_1_1"), 15)
# Translation 34
Translation_34_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_15_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_8 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_16_1")], [model.selection("SOLID", "Translation_15_1")])
+Intersection_8 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_16_1"), model.selection("SOLID", "Translation_15_1")])
Translation_34 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_8_1")], model.selection("EDGE", "Intersection_8_1_6"), 15)
# Translation 35
Translation_35_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_17_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_9 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_18_1")], [model.selection("SOLID", "Translation_17_1")])
+Intersection_9 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_18_1"), model.selection("SOLID", "Translation_17_1")])
Translation_35 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_9_1")], model.selection("EDGE", "Axis_1"), 15)
#Translation 36