#include <ModuleBase_WidgetMultiSelector.h>
#include <ModuleBase_WidgetShapeSelector.h>
-#include <ModuleBase_FilterNoDegeneratedEdge.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IViewer.h>
}
//********************************************************************
-void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup)
+void ModuleBase_WidgetMultiSelector::storeAttributeValue()
{
DataPtr aData = myFeature->data();
AttributeSelectionListPtr aSelectionListAttr =
if (aSelectionListAttr.get() == NULL)
return;
- if (isBackup) {
- mySelectionType = aSelectionListAttr->selectionType();
- mySelection.clear();
- for (int i = 0; i < aSelectionListAttr->size(); i++) {
- AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
- mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
- }
+ mySelectionType = aSelectionListAttr->selectionType();
+ mySelection.clear();
+ int aSize = aSelectionListAttr->size();
+ for (int i = 0; i < aSelectionListAttr->size(); i++) {
+ AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+ mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
}
- else {
- aSelectionListAttr->clear();
- // Store shapes type
- aSelectionListAttr->setSelectionType(mySelectionType);
+}
- // Store selection in the attribute
- foreach (GeomSelection aSelec, mySelection) {
- aSelectionListAttr->append(aSelec.first, aSelec.second);
- }
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
+{
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+ if (aSelectionListAttr.get() == NULL)
+ return;
+ aSelectionListAttr->clear();
+
+ // Store shapes type
+ aSelectionListAttr->setSelectionType(mySelectionType);
+
+ // Store selection in the attribute
+ int aSize = mySelection.size();
+ foreach (GeomSelection aSelec, mySelection) {
+ aSelectionListAttr->append(aSelec.first, aSelec.second);
}
}
QIntList aList;
aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
myWorkshop->activateSubShapesSelection(aList);
-
- // it is necessary to filter the selected edges to be non-degenerated
- // it is not possible to build naming name for such edges
- if (aNewType == "Edges") {
- myEdgesTypeFilter = new ModuleBase_FilterNoDegeneratedEdge();
- aViewer->addSelectionFilter(myEdgesTypeFilter);
- }
- else {
- aViewer->removeSelectionFilter(myEdgesTypeFilter);
- }
-
} else {
myWorkshop->deactivateSubShapesSelection();
- aViewer->removeSelectionFilter(myEdgesTypeFilter);
}
activateFilters(myWorkshop, myIsActive);
#include <ModuleBase.h>
#include <ModuleBase_WidgetValidated.h>
-#include <ModuleBase_FilterNoDegeneratedEdge.h>
#include <GeomAPI_Shape.h>
#include <ModelAPI_Result.h>
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
- /// \param isBackup a boolean flag, if true, store values from the attribute
- /// to backup, otherwise set the backed up values to the attribute
- virtual void backupAttributeValue(const bool isBackup);
+ virtual void storeAttributeValue();
+
+ /// Creates a backup of the current values of the attribute
+ /// It should be realized in the specific widget because of different
+ /// parameters of the current attribute
+ /// \param theValid a boolean flag, if restore happens for valid parameters
+ virtual void restoreAttributeValue(const bool theValid);
/// Set current shape type for selection
void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
/// An action for pop-up menu in a list control
QAction* myCopyAction;
- /// A filter for the Edges type, which avoid the generated edges selection
- Handle(ModuleBase_FilterNoDegeneratedEdge) myEdgesTypeFilter;
-
/// backup parameters of the model attribute. The class processes three types of attribute:
/// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
/// values are reserved in the backup
}
//********************************************************************
-void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
+void ModuleBase_WidgetShapeSelector::storeAttributeValue()
{
DataPtr aData = myFeature->data();
AttributePtr anAttribute = myFeature->attribute(attributeID());
- if (isBackup) {
- myObject = GeomValidators_Tools::getObject(anAttribute);
- myShape = getShape();
- myRefAttribute = NULL;
- myIsObject = false;
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- myIsObject = aRefAttr->isObject();
- myRefAttribute = aRefAttr->attr();
- }
- myExternalObject = NULL;
+ myObject = GeomValidators_Tools::getObject(anAttribute);
+ myShape = getShape();
+ myRefAttribute = NULL;
+ myIsObject = false;
+ AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+ if (aRefAttr) {
+ myIsObject = aRefAttr->isObject();
+ myRefAttribute = aRefAttr->attr();
}
- else {
- storeAttributeValues(myObject, myShape);
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- if (!myIsObject)
- aRefAttr->setAttr(myRefAttribute);
- }
- if (myExternalObject.get()) {
- DocumentPtr aDoc = myExternalObject->document();
- FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
- if (aFeature.get() != NULL) {
- aDoc->removeFeature(aFeature);
- }
- }
+}
+
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
+{
+ DataPtr aData = myFeature->data();
+ AttributePtr anAttribute = myFeature->attribute(attributeID());
+
+ storeAttributeValues(myObject, myShape);
+ AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+ if (aRefAttr) {
+ if (!myIsObject)
+ aRefAttr->setAttr(myRefAttribute);
}
}
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
- /// \param isBackup a boolean flag, if true, store values from the attribute
- /// to backup, otherwise set the backed up values to the attribute
- virtual void backupAttributeValue(const bool isBackup);
+ virtual void storeAttributeValue();
+
+ /// Creates a backup of the current values of the attribute
+ /// It should be realized in the specific widget because of different
+ /// parameters of the current attribute
+ /// \param theValid a boolean flag, if restore happens for valid parameters
+ virtual void restoreAttributeValue(const bool theValid);
/// Computes and updates name of selected object in the widget
void updateSelectionName();
AttributePtr myRefAttribute;
/// A boolean value whether refAttr uses reference of object
bool myIsObject;
- /// An external object
- ObjectPtr myExternalObject;
};
#endif
bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
{
// stores the current values of the widget attribute
- backupAttributeValue(true);
+ storeAttributeValue();
// saves the owner value to the widget attribute
setSelection(theOwner);
bool aValid = isValidAttribute();
// restores the current values of the widget attribute
- backupAttributeValue(false);
+ restoreAttributeValue(aValid);
return aValid;
}
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
- /// \param isBackup a boolean flag, if true, store values from the attribute
- /// to backup, otherwise set the backed up values to the attribute
- virtual void backupAttributeValue(const bool isBackup) = 0;
+ virtual void storeAttributeValue() = 0;
+
+ /// Creates a backup of the current values of the attribute
+ /// It should be realized in the specific widget because of different
+ /// parameters of the current attribute
+ /// \param theValid a boolean flag, if restore happens for valid parameters
+ virtual void restoreAttributeValue(const bool theValid) = 0;
/// Fills the attribute with the value of the selected owner
/// \param theOwner a selected owner
virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner) = 0;
+ virtual void removePresentations() {};
+
/// Checks the current attibute in all attribute validators
// \return true if all validators return that the attribute is valid
bool isValidAttribute() const;
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if ((!aSPFeature) && (!theShape->isNull())) {
- ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
- aSelectedObject, mySketch);
- if (aObj) {
- aSelectedObject = aObj;
- myExternalObject = aObj;
+ createExternal(theSelectedObject, theShape);
+
+ if (myExternalObject) {
+ aSelectedObject = myExternalObject;
} else
return false;
}
#include "PartSet.h"
-#include <ModuleBase_WidgetShapeSelector.h>
+#include <PartSet_WidgetShapeSelector.h>
#include <ModelAPI_CompositeFeature.h>
/**
* \ingroup Modules
-* Customosation of ModuleBase_WidgetShapeSelector in order to provide
+* Customosation of PartSet_WidgetShapeSelector in order to provide
* working with constraints.
*/
-class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public ModuleBase_WidgetShapeSelector
+class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public PartSet_WidgetShapeSelector
{
Q_OBJECT
public:
/// \param theParentId is Id of a parent of the current attribute
PartSet_WidgetConstraintShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData, const std::string& theParentId)
- : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
+ : PartSet_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
virtual ~PartSet_WidgetConstraintShapeSelector() {}
/// Set sketcher
/// \param theSketch a sketcher object
- void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+ //void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
/// Retrurns installed sketcher
- CompositeFeaturePtr sketch() const { return mySketch; }
+ //CompositeFeaturePtr sketch() const { return mySketch; }
protected:
/// Store the values to the model attribute of the widget. It casts this attribute to
/// \param theShape a selected shape, which is used in the selection attribute
virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-private:
+//private:
/// Pointer to a sketch
- CompositeFeaturePtr mySketch;
+ //CompositeFeaturePtr mySketch;
};
#endif
\ No newline at end of file
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
+#include <ModuleBase_IWorkshop.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
{
ObjectPtr aSelectedObject = theSelectedObject;
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) {
// Processing of external (non-sketch) object
- ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(aShape->impl<TopoDS_Shape>(),
- aSelectedObject, mySketch);
- if (aObj) {
- PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
- aSelectedObject = aObj;
- myExternalObject = aObj;
- } else
+ createExternal(theSelectedObject, theShape);
+ if (myExternalObject)
+ aSelectedObject = myExternalObject;
+ else
return false;
} else {
// Processing of sketch object
return ModuleBase_WidgetShapeSelector::storeAttributeValues(aSelectedObject, aShape);
}
+//********************************************************************
+void PartSet_WidgetShapeSelector::storeAttributeValue()
+{
+ /// this is a temporary code, will be removed when master is merged to this branch
+ /*XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ aWorkshop->displayer()->enableUpdateViewer(false);
+ */
+ ModuleBase_WidgetShapeSelector::storeAttributeValue();
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
+{
+ ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
+ //if (!theValid)
+ removeExternal();
+ /*
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ aWorkshop->displayer()->enableUpdateViewer(false);//->erase(myExternalObject);
+ aWorkshop->displayer()->enableUpdateViewer(true);*/
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject,
+ GeomShapePtr theShape)
+{
+ ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+ theSelectedObject, mySketch);
+ if (aObj != myExternalObject) {
+ removeExternal();
+ myExternalObject = aObj;
+ }
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::removeExternal()
+{
+ if (myExternalObject.get()) {
+ DocumentPtr aDoc = myExternalObject->document();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
+ if (aFeature.get() != NULL) {
+ aDoc->removeFeature(aFeature);
+ }
+ myExternalObject = NULL;
+ }
+}
/// \param theShape a selected shape, which is used in the selection attribute
virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-private:
+ /// Creates a backup of the current values of the attribute
+ /// It should be realized in the specific widget because of different
+ /// parameters of the current attribute
+ virtual void storeAttributeValue();
+
+ /// Creates a backup of the current values of the attribute
+ /// It should be realized in the specific widget because of different
+ /// parameters of the current attribute
+ /// \param theValid a boolean flag, if restore happens for valid parameters
+ void restoreAttributeValue(const bool theValid);
+
+ // Removes the external presentation from the model
+ /// \param theSelectedObject an object
+ /// \param theShape a selected shape, which is used in the selection attribute
+ void createExternal(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+
+ // Removes the external presentation from the model
+ void removeExternal();
+
+protected:
/// Pointer to a sketch
CompositeFeaturePtr mySketch;
+
+ /// An external object
+ ObjectPtr myExternalObject;
};
#endif
\ No newline at end of file
myLabel->installEventFilter(this);
}
-void PartSet_WidgetSketchLabel::backupAttributeValue(const bool isBackup)
+void PartSet_WidgetSketchLabel::storeAttributeValue()
+{
+}
+
+void PartSet_WidgetSketchLabel::restoreAttributeValue(const bool theValid)
{
// it is not necessary to save the previous plane value because the plane is chosen once
- if (!isBackup) {
- DataPtr aData = feature()->data();
- AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
- if (aSelAttr) {
- ResultPtr anEmptyResult;
- GeomShapePtr anEmptyShape;
- aSelAttr->setValue(anEmptyResult, anEmptyShape);
- }
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ ResultPtr anEmptyResult;
+ GeomShapePtr anEmptyShape;
+ aSelAttr->setValue(anEmptyResult, anEmptyShape);
}
}
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
- /// \param isBackup a boolean flag, if true, store values from the attribute
- /// to backup, otherwise set the backed up values to the attribute
- virtual void backupAttributeValue(const bool isBackup);
+ virtual void storeAttributeValue();
+
+ /// Creates a backup of the current values of the attribute
+ /// It should be realized in the specific widget because of different
+ /// parameters of the current attribute
+ /// \param theValid a boolean flag, if restore happens for valid parameters
+ virtual void restoreAttributeValue(const bool theValid);
/// Fills the attribute with the value of the selected owner
/// \param theOwner a selected owner
shape_types="edge vertex">
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
- <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
+ <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
<validator id="GeomValidators_EdgeOrVertex"/>
</sketch_shape_selector>