//=================================================================================================
void FeaturesPlugin_CompositeBoolean::initAttributes()
{
+ AttributeSelectionListPtr aSelection =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
+ LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+
data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
+ SKETCH_OBJECT_ID());
// Boolean works with solids always.
data()->addAttribute(BOOLEAN_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
- AttributeSelectionListPtr aSelection = data()->selectionList(BOOLEAN_OBJECTS_ID());
+ aSelection = data()->selectionList(BOOLEAN_OBJECTS_ID());
aSelection->setSelectionType("SOLID");
initMakeSolidsAttributes();
//=================================================================================================
void FeaturesPlugin_CompositeBoolean::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
{
+ AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+ if (aFacesSelectionList.get() && aFacesSelectionList->size() > 0)
+ aFacesSelectionList->clear();
}
//=================================================================================================
//=================================================================================================
void FeaturesPlugin_CompositeBoolean::execute()
{
+ /// feature extrusion does not have the next attribute
+ AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+ if (aFacesSelectionList.get() && !aFacesSelectionList->isInitialized()) {
+ AttributeReferencePtr aSketchAttr = reference(SKETCH_OBJECT_ID());
+ if (aSketchAttr.get() && aSketchAttr->isInitialized())
+ setSketchObjectToList();
+ }
+
// Getting faces to create solids.
std::shared_ptr<ModelAPI_Feature> aSketchFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
reference(SKETCH_OBJECT_ID())->value());
}
}
}
+
+//=================================================================================================
+void FeaturesPlugin_CompositeBoolean::setSketchObjectToList()
+{
+ std::shared_ptr<ModelAPI_Feature> aSketchFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
+ reference(SKETCH_OBJECT_ID())->value());
+
+ if(aSketchFeature.get() && !aSketchFeature->results().empty()) {
+ ResultPtr aSketchRes = aSketchFeature->results().front();
+ ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSketchRes);
+ if(aConstruction.get()) {
+ AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+ if (aFacesSelectionList.get() && aFacesSelectionList->size() == 0)
+ aFacesSelectionList->append(aSketchRes, std::shared_ptr<GeomAPI_Shape>());
+ }
+ }
+}
return MY_SKETCH_OBJECT_ID;
}
+ /// attribute name of references sketch entities list, it should contain a sketch result or
+ /// a pair a sketch result to sketch face
+ inline static const std::string& LIST_ID()
+ {
+ static const std::string MY_GROUP_LIST_ID("base");
+ return MY_GROUP_LIST_ID;
+ }
+
/// Attribute name of sketch feature.
inline static const std::string& SKETCH_SELECTION_ID()
{
GeomAlgoAPI_MakeShape& theMakeShape,
GeomAPI_DataMapOfShapeShape& theMapOfShapes);
+ /// Set the sub-object to list of exturusion base.
+ void setSketchObjectToList();
+
protected:
/// Type of boolean operation.
GeomAlgoAPI_Boolean::OperationType myBooleanOperationType;
LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
// extrusion works with faces always
aSelection->setSelectionType("FACE");
- ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
- FeaturesPlugin_Extrusion::LIST_ID());
-
data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
// Getting faces.
ListOfShape aFacesList;
- //AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) {
AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex);
std::shared_ptr<GeomAPI_Shape> aFaceShape = aFaceSel->value();
1. Planar face of non-sketch object or a plane. Sketch creation will be started.<br />
2. An existing sketch face or contour. Extrusion will be filled by it.<br />
3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it."
- icon=":icons/sketch.png"
- tooltip="Create or edit a sketch"
shape_types="face objects">
</sketch_launcher>
<composite_multi_selector id="base"
<source>
<groupbox title="Extrusion">
<sketch_launcher id="sketch"
- label="Sketch"
- icon=":icons/sketch.png"
- tooltip="Create or edit a sketch">
+ attribute_list_id="base"
+ label="Select:<br />
+1. Planar face of non-sketch object or a plane. Sketch creation will be started.<br />
+2. An existing sketch face or contour. Extrusion will be filled by it.<br />
+3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it."
+ shape_types="face objects">
</sketch_launcher>
+ <composite_multi_selector id="base"
+ label="Select a sketch face"
+ icon=":icons/sketch.png"
+ tooltip="Select a sketch face"
+ type_choice="Faces Objects">
+ <validator id="FeaturesPlugin_ValidatorExtrusionBase" parameters="Sketch"/>
+ </composite_multi_selector>
<toolbox id="CreationMethod">
<box id="BySizes" title="By sizes" icon=":icons/dimension_up_down_32x32.png">
<groupbox>
#include <GeomAPI_Face.h>
+#include <GeomAbs_SurfaceType.hxx>
+
#include <Events_Error.h>
#include <QString>
typedef std::map<std::string, GeomAbs_SurfaceType> FaceTypes;
static FaceTypes MyFaceTypes;
-GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType)
+GeomAbs_SurfaceType faceType(const std::string& theType)
{
if (MyFaceTypes.size() == 0) {
MyFaceTypes["plane"] = GeomAbs_Plane;
#include "GeomValidators.h"
#include "ModelAPI_AttributeValidator.h"
-#include <GeomAbs_SurfaceType.hxx>
-
/**
* \ingroup Validators
* A validator of selection
GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
std::string& theError) const;
-protected:
- /// Convert string to TypeOfFace value
- /// \param theType a string value
- GEOMVALIDATORS_EXPORT static GeomAbs_SurfaceType faceType(const std::string& theType);
};
#endif
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeRefAttrList.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_ResultCompSolid.h>
#include <QColor>
#include <sstream>
+#include <string>
const double tolerance = 1e-7;
return anAttributeId;
}
+void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
+ const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
+ const bool theTemporarily)
+{
+ if (!theAttribute.get())
+ return;
+
+ std::string aType = theAttribute->attributeType();
+ if (aType == ModelAPI_AttributeReference::typeId()) {
+ AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+ ObjectPtr aObject = aRef->value();
+ if (!(aObject && aObject->isSame(theObject))) {
+ aRef->setValue(theObject);
+ }
+ } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+
+ AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
+ if (anAttribute.get())
+ aRefAttr->setAttr(anAttribute);
+ else {
+ ObjectPtr aObject = aRefAttr->object();
+ if (!(aObject && aObject->isSame(theObject))) {
+ aRefAttr->setObject(theObject);
+ }
+ }
+ } else if (aType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr aSelectAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aSelectAttr.get() != NULL) {
+ aSelectAttr->setValue(aResult, theShape, theTemporarily);
+ }
+ }
+ if (aType == ModelAPI_AttributeSelectionList::typeId()) {
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (!aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
+ aSelectionListAttr->append(aResult, theShape, theTemporarily);
+ }
+ else if (aType == ModelAPI_AttributeRefList::typeId()) {
+ AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+ if (!aRefListAttr->isInList(theObject))
+ aRefListAttr->append(theObject);
+ }
+ else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+ AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
+ AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
+
+ if (anAttribute.get()) {
+ if (!aRefAttrListAttr->isInList(anAttribute))
+ aRefAttrListAttr->append(anAttribute);
+ }
+ else {
+ if (!aRefAttrListAttr->isInList(theObject))
+ aRefAttrListAttr->append(theObject);
+ }
+ }
+}
+
} // namespace ModuleBase_Tools
class ModuleBase_ParamSpinBox;
class ModuleBase_IWorkshop;
+class GeomAPI_Shape;
+
namespace ModuleBase_Tools {
/*
/// \theParameters a list of parameter names
MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
const FeaturePtr& theFeature);
+
+/// Set the object to the attribute depending on the attribute type. If it is a list,
+/// the values are appended if they are not in the list yet.
+/// \param theAttribute an attribute where the object and shape are set
+/// \param theObject an object
+/// \param theShape a shape
+/// \param theWorkshop to find an attribute for the given shape for attribute reference
+/// \param theTemporarily if it is true, do not store and name the added in the data framework
+/// It is useful for attribute selection
+MODULEBASE_EXPORT void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
+ const std::shared_ptr<GeomAPI_Shape>& theShape,
+ ModuleBase_IWorkshop* theWorkshop,
+ const bool theTemporarily = false);
}
#endif
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_Tools.h>
#include <Config_WidgetAPI.h>
}
//********************************************************************
-void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
+void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theObject,
GeomShapePtr theShape)
{
DataPtr aData = myFeature->data();
- AttributePtr anAttribute = aData->attribute(attributeID());
- std::string aType = anAttribute->attributeType();
- if (aType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
- if (!aSelectionListAttr->isInList(aResult, theShape, myIsInValidate))
- aSelectionListAttr->append(aResult, theShape, myIsInValidate);
- }
- else if (aType == ModelAPI_AttributeRefList::typeId()) {
- AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
- if (!aRefListAttr->isInList(theSelectedObject))
- aRefListAttr->append(theSelectedObject);
- }
- else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
- AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
- AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
-
- if (anAttribute.get()) {
- if (!aRefAttrListAttr->isInList(anAttribute))
- aRefAttrListAttr->append(anAttribute);
- }
- else {
- if (!aRefAttrListAttr->isInList(theSelectedObject))
- aRefAttrListAttr->append(theSelectedObject);
- }
- }
+ ModuleBase_Tools::setObject(aData->attribute(attributeID()), theObject, theShape,
+ myWorkshop, myIsInValidate);
}
//********************************************************************
/// Append the values to the model attribute of the widget. It casts this attribute to
/// the specific type and set the given values
- /// \param theSelectedObject an object
+ /// \param theObject an object
/// \param theShape a selected shape, which is used in the selection attribute
/// \return true if it is succeed
- void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+ void setObject(ObjectPtr theObject, GeomShapePtr theShape);
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
}
//********************************************************************
-void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
+void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObject,
GeomShapePtr theShape)
{
DataPtr aData = myFeature->data();
- std::string aType = aData->attribute(attributeID())->attributeType();
- if (aType == ModelAPI_AttributeReference::typeId()) {
- AttributeReferencePtr aRef = aData->reference(attributeID());
- ObjectPtr aObject = aRef->value();
- if (!(aObject && aObject->isSame(theSelectedObject))) {
- aRef->setValue(theSelectedObject);
- }
- } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-
- AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
- if (anAttribute.get())
- aRefAttr->setAttr(anAttribute);
- else {
- ObjectPtr aObject = aRefAttr->object();
- if (!(aObject && aObject->isSame(theSelectedObject))) {
- aRefAttr->setObject(theSelectedObject);
- }
- }
- } else if (aType == ModelAPI_AttributeSelection::typeId()) {
- AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
- if (aSelectAttr.get() != NULL) {
- aSelectAttr->setValue(aResult, theShape);
- }
- }
+ ModuleBase_Tools::setObject(aData->attribute(attributeID()), theObject, theShape,
+ myWorkshop, myIsInValidate);
}
//********************************************************************
/// Store the values to the model attribute of the widget. It casts this attribute to
/// the specific type and set the given values
- /// \param theSelectedObject an object
+ /// \param theObject an object
/// \param theShape a selected shape, which is used in the selection attribute
/// \return true if it is succeed
- virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+ virtual void setObject(ObjectPtr theObject, GeomShapePtr theShape);
/// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
/// \return a shape
for (; anIt != aLast; anIt++) {
ModuleBase_ViewerPrs aValue = *anIt;
if (isValidInFilters(aValue))
- aProcessed = setSelectionCustom(aValue) || aProcessed;
+ aProcessed = setBaseAttributeSelection(aValue) || aProcessed;
}
if (aProcessed) {
emit valuesChanged();
}
//********************************************************************
-void PartSet_WidgetSketchCreator::setObject(ObjectPtr theSelectedObject,
+void PartSet_WidgetSketchCreator::setObject(ObjectPtr theObject,
GeomShapePtr theShape)
{
- // do nothing because all processing is in onSelectionChanged()
+ DataPtr aData = myFeature->data();
+ ModuleBase_Tools::setObject(aData->attribute(attributeID()), theObject, theShape,
+ myWorkshop, myIsInValidate);
+
+ //::setObject(aData->attribute(attributeID()), theObject, theShape);
}
bool PartSet_WidgetSketchCreator::startSketchOperation(const QList<ModuleBase_ViewerPrs>& theValues)
}
}
}
+
+bool PartSet_WidgetSketchCreator::setBaseAttributeSelection(const ModuleBase_ViewerPrs& theValue)
+{
+ bool isDone = false;
+ ObjectPtr anObject;
+ GeomShapePtr aShape;
+ getGeomSelection(theValue, anObject, aShape);
+
+ std::string anAttributeId = myAttributeListID;
+ DataPtr aData = myFeature->data();
+ ModuleBase_Tools::setObject(aData->attribute(anAttributeId), anObject, aShape,
+ myWorkshop, false);
+ return true;
+}
class QLabel;
class QLineEdit;
class PartSet_Module;
+class ModelAPI_Tools;
class ModuleBase_Operation;
class ModuleBase_IWorkshop;
class PartSet_PreviewPlanes;
/// Store the values to the model attribute of the widget. It casts this attribute to
/// the specific type and set the given values
- /// \param theSelectedObject an object
+ /// \param theObject an object
/// \param theShape a selected shape, which is used in the selection attribute
/// \return true if it is succeed
- virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+ virtual void setObject(ObjectPtr theObject, GeomShapePtr theShape);
private:
/// Returns true if the selection mode is active. This is when composition feature has no
/// \return true if the sketch is started
bool startSketchOperation(const QList<ModuleBase_ViewerPrs>& theValues);
+ /// Appends the selection to the sketch base attribute
+ /// \param theValue a selection value from the viewer
+ /// \return true if the value is set
+ bool setBaseAttributeSelection(const ModuleBase_ViewerPrs& theValue);
+
private:
std::string myAttributeListID;