#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
#include <GeomAlgoAPI_Extrusion.h>
void FeaturesPlugin_Extrusion::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeReference::type());
+ data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
}
void FeaturesPlugin_Extrusion::execute()
{
- boost::shared_ptr<ModelAPI_AttributeReference> aFaceRef = boost::dynamic_pointer_cast<
- ModelAPI_AttributeReference>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
+ boost::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
if (!aFaceRef)
return;
- boost::shared_ptr<GeomAPI_Shape> aFace;
- boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = boost::dynamic_pointer_cast<
- ModelAPI_ResultConstruction>(aFaceRef->value());
- if (aConstr) {
- aFace = aConstr->shape();
- }
- if (!aFace) {
- // Check for body
- boost::shared_ptr<ModelAPI_ResultBody> aBody = boost::dynamic_pointer_cast<
- ModelAPI_ResultBody>(aFaceRef->value());
- if (aBody)
- aFace = aBody->shape();
- }
- if (!aFace)
- return;
+ boost::shared_ptr<GeomAPI_Shape> aFace =
+ boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
aSize = -aSize;
+
boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
setResult(aResult);
icon=":icons/sketch.png"
tooltip="Select a face for extrusion"
activate="true"
- shape_types="face wire"
+ shape_types="face wire edge"
use_subshapes="true"
/>
<doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="0" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
#include <Model_AttributeRefList.h>
#include <Model_AttributeBoolean.h>
#include <Model_AttributeString.h>
+#include <ModelAPI_AttributeSelection.h>
#include <Model_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
return aRes;
}
+boost::shared_ptr<ModelAPI_AttributeSelection> Model_Data::selection(const std::string& theID)
+{
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ if (aFound == myAttrs.end()) {
+ // TODO: generate error on unknown attribute request and/or add mechanism for customization
+ return boost::shared_ptr<ModelAPI_AttributeSelection>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeSelection> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::string& theID)
{
std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
/// Returns the attribute that contains reference to a feature
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
reference(const std::string& theID);
+ /// Returns the attribute that contains selection to a shape
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection>
+ selection(const std::string& theID);
/// Returns the attribute that contains reference to an attribute of a feature
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
refattr(const std::string& theID);
class ModelAPI_Document;
class ModelAPI_Attribute;
class ModelAPI_Feature;
+class ModelAPI_AttributeSelection;
class GeomAPI_Shape;
/**\class ModelAPI_Data
virtual boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
/// Returns the attribute that contains reference to a feature
virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
+ /// Returns the attribute that contains selection to a shape
+ virtual boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
/// Returns the attribute that contains reference to an attribute of a feature
virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
/// Returns the attribute that contains list of references to features
#include <ModelAPI_Object.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
#include <Config_WidgetAPI.h>
#include <GeomAPI_Shape.h>
//********************************************************************
ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
{
+ activateSelection(false);
}
//********************************************************************
return false;
DataPtr aData = myFeature->data();
- boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
- ModelAPI_AttributeReference>(aData->attribute(attributeID()));
+ if (myUseSubShapes) {
+ boost::shared_ptr<ModelAPI_AttributeSelection> aSelect =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aData->attribute(attributeID()));
+
+ ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(mySelectedObject);
+ if (aBody)
+ aSelect->setValue(aBody, myShape);
+ } else {
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
- ObjectPtr aObject = aRef->value();
- if (!(aObject && aObject->isSame(mySelectedObject))) {
- aRef->setValue(mySelectedObject);
- updateObject(myFeature);
+ ObjectPtr aObject = aRef->value();
+ if (!(aObject && aObject->isSame(mySelectedObject))) {
+ aRef->setValue(mySelectedObject);
+ updateObject(myFeature);
+ }
}
return true;
}
bool ModuleBase_WidgetShapeSelector::restoreValue()
{
DataPtr aData = myFeature->data();
- boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
-
bool isBlocked = this->blockSignals(true);
- mySelectedObject = aRef->value();
+ if (myUseSubShapes) {
+ boost::shared_ptr<ModelAPI_AttributeSelection> aSelect = aData->selection(attributeID());
+ if (aSelect) {
+ mySelectedObject = aSelect->context();
+ myShape = aSelect->value();
+ }
+ } else {
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
+ mySelectedObject = aRef->value();
+ }
updateSelectionName();
this->blockSignals(isBlocked);
#include "ModuleBase_ModelWidget.h"
#include <ModelAPI_Object.h>
+#include <GeomAPI_Shape.h>
#include <TopAbs_ShapeEnum.hxx>
ModuleBase_IWorkshop* myWorkshop;
ObjectPtr mySelectedObject;
+ boost::shared_ptr<GeomAPI_Shape> myShape;
+
QStringList myShapeTypes;
/// If true then local selector has to be activated in context
Handle(AIS_InteractiveContext) aAIS = myWorkshop->viewer()->AISContext();
if (!aAIS->HasOpenedContext())
aAIS->OpenLocalContext();
- foreach(int aType, theTypes)
+ foreach(int aType, theTypes) {
aAIS->ActivateStandardMode((TopAbs_ShapeEnum)aType);
+ }
}
void XGUI_ModuleConnector::deactivateSubShapesSelection()