data()->addAttribute(FeaturesPlugin_Extrusion::TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(FeaturesPlugin_Extrusion::FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
- //data()->addAttribute(FeaturesPlugin_Extrusion::AXIS_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
-
data()->addAttribute(FeaturesPlugin_Extrusion::FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
data()->addAttribute(FeaturesPlugin_Extrusion::TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeRefList.h>
//=================================================================================================
FeaturesPlugin_ExtrusionCut::FeaturesPlugin_ExtrusionCut()
//=================================================================================================
void FeaturesPlugin_ExtrusionCut::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_ExtrusionCut::SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
- data()->addAttribute(FeaturesPlugin_ExtrusionCut::TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(FeaturesPlugin_ExtrusionCut::FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
- data()->addAttribute(FeaturesPlugin_ExtrusionCut::AXIS_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
+ data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(FeaturesPlugin_ExtrusionCut::FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
- data()->addAttribute(FeaturesPlugin_ExtrusionCut::TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_ExtrusionCut::FROM_OBJECT_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_ExtrusionCut::TO_OBJECT_ID());
- AttributeSelectionListPtr aSelection =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
- FeaturesPlugin_ExtrusionCut::LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+ data()->addAttribute(CUTLIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+
// extrusion works with faces always
+ AttributeSelectionListPtr aSelection = data()->selectionList(CUTLIST_ID());
aSelection->setSelectionType("SOLID");
}
+
+std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::addFeature(std::string theID)
+{
+ std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
+ if (aNew) {
+ data()->reference(SKETCH_OBJECT_ID())->setValue(aNew);
+ }
+ // set as current also after it becomes sub to set correctly enabled for other sketch subs
+ //document()->setCurrentFeature(aNew, false);
+ return aNew;
+}
+
+
+int FeaturesPlugin_ExtrusionCut::numberOfSubs() const
+{
+ ObjectPtr aObj = data()->reference(SKETCH_OBJECT_ID())->value();
+ return aObj.get()? 1 : 0;
+}
+
+std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::subFeature(const int theIndex) const
+{
+ if (theIndex == 0)
+ return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
+ return std::shared_ptr<ModelAPI_Feature>();
+}
+
+int FeaturesPlugin_ExtrusionCut::subFeatureId(const int theIndex) const
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = subFeature(theIndex);
+ if (aFeature.get())
+ return aFeature->data()->featureId();
+ return -1;
+}
+
+bool FeaturesPlugin_ExtrusionCut::isSub(ObjectPtr theObject) const
+{
+ // check is this feature of result
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (!aFeature)
+ return false;
+
+ ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value();
+ return aSub == theObject;
+}
+
+void FeaturesPlugin_ExtrusionCut::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
+{
+}
+
//=================================================================================================
void FeaturesPlugin_ExtrusionCut::execute()
{
#include <FeaturesPlugin.h>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
/** \class FeaturesPlugin_ExtrusionCut
* \ingroup Plugins
*/
-class FeaturesPlugin_ExtrusionCut : public ModelAPI_Feature
+class FeaturesPlugin_ExtrusionCut : public ModelAPI_CompositeFeature
{
public:
/// Revolution kind.
/// 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()
+ inline static const std::string& CUTLIST_ID()
{
- static const std::string MY_GROUP_LIST_ID("main_objects");
- return MY_GROUP_LIST_ID;
+ static const std::string MY_CUT_LIST_ID("cut_objects");
+ return MY_CUT_LIST_ID;
}
/// attribute name of an object to which the extrusion grows
return MY_TO_OBJECT_ID;
}
- /// Attribute name of an object to which the extrusion grows.
- inline static const std::string& AXIS_OBJECT_ID()
- {
- static const std::string MY_TO_OBJECT_ID("axis_object");
- return MY_TO_OBJECT_ID;
- }
-
/// attribute name of extrusion size
inline static const std::string& TO_SIZE_ID()
{
return MY_TO_SIZE_ID;
}
- /// attribute name of extrusion size
- inline static const std::string& FROM_SIZE_ID()
- {
- static const std::string MY_FROM_SIZE_ID("from_size");
- return MY_FROM_SIZE_ID;
- }
-
/// attribute name of an object to which the extrusion grows
inline static const std::string& TO_OBJECT_ID()
{
return MY_FROM_OBJECT_ID;
}
+ /// attribute name of extrusion size
+ inline static const std::string& FROM_SIZE_ID()
+ {
+ static const std::string MY_FROM_SIZE_ID("from_size");
+ return MY_FROM_SIZE_ID;
+ }
+
/// Returns the kind of a feature
FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
{
/// Use plugin manager for features creation.
FeaturesPlugin_ExtrusionCut();
+
+ /// appends a feature to the sketch sub-elements container
+ FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
+
+ /// Returns the number of sub-elements
+ FEATURESPLUGIN_EXPORT virtual int numberOfSubs() const;
+
+ /// Returns the sub-feature by zero-base index
+ FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const;
+
+ /// Returns the sub-feature unique identifier in this composite feature by zero-base index
+ FEATURESPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
+
+ /// Returns true if feature or reuslt belong to this composite feature as subs
+ FEATURESPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
+
+ /// This method to inform that sub-feature is removed and must be removed from the internal data
+ /// structures of the owner (the remove from the document will be done outside just after)
+ FEATURESPLUGIN_EXPORT virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
};
#endif
<source>
<groupbox title="Extrusion">
- <shape_selector id="main_objects"
- label="Select a planar face"
+ <sketch_launcher id="sketch"
+ label="Sketch"
icon=":icons/sketch.png"
- tooltip="Select a destination element"
- shape_types="face edge vertex"
- default="<sketch>"
- />
+ tooltip="Create or edit a sketch">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </sketch_launcher>
<groupbox title="From">
<shape_selector id="from_object"
icon=":icons/plane.png"
default="<sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
- <doublevalue
- id="from_size"
- label="Size"
- min="0"
- step="1.0"
- default="0"
+ <doublevalue id="from_size" label="Size"
+ min="0" step="1.0" default="0"
icon=":icons/dimension_down.png"
tooltip="Height">
</doublevalue>
default="<sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
- <doublevalue
- id="to_size"
- label="Size"
- min="0"
- step="1.0"
- default="0"
+ <doublevalue id="to_size"
+ label="Size" min="0" step="1.0" default="0"
icon=":icons/dimension_up.png"
tooltip="Height">
</doublevalue>
</groupbox>
</groupbox>
- <multi_selector id="main_objects"
+ <multi_selector id="cut_objects"
label="Cut from:"
icon=":icons/cut_shape.png"
tooltip="Objects to Cut"
if (aCmd->isCheckable() && !aCmd->isChecked())
return;
launchOperation(aCmd->data().toString());
+ emit operationLaunched();
}
/// \param theObjectBrowser a pinter on Object Browser widget\r
virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}\r
\r
+ /// Creates a new operation\r
+ /// \param theCmdId the operation name\r
+ virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);\r
+\r
+ /// Sends the operation for launching\r
+ /// \param theOperation the operation\r
+ virtual void sendOperation(ModuleBase_Operation* theOperation);\r
+\r
+signals:\r
+ void operationLaunched();\r
+\r
public slots:\r
/// Called on call of command corresponded to a feature\r
virtual void onFeatureTriggered();\r
virtual void onSelectionChanged() {}\r
\r
protected:\r
- /// Sends the operation for launching\r
- /// \param theOperation the operation\r
- virtual void sendOperation(ModuleBase_Operation* theOperation);\r
-\r
- /// Creates a new operation\r
- /// \param theCmdId the operation name\r
- virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);\r
-\r
/// Register validators for this module\r
virtual void registerValidators() {}\r
\r
PartSet_DocumentDataModel.h
PartSet_PartDataModel.h
PartSet_DataTreeModel.h
+ PartSet_WidgetSketchCreator.h
)
SET(PROJECT_SOURCES
PartSet_MenuMgr.cpp
PartSet_DocumentDataModel.cpp
PartSet_PartDataModel.cpp
+ PartSet_WidgetSketchCreator.cpp
)
SET(PROJECT_RESOURCES
#include "PartSet_WidgetMultiSelector.h"
#include "PartSet_WidgetEditor.h"
#include "PartSet_WidgetFileSelector.h"
+#include "PartSet_WidgetSketchCreator.h"
#include "PartSet_SketcherMgr.h"
#include "PartSet_MenuMgr.h"
aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId);
} else if (theType == "export_file_selector") {
aWgt = new PartSet_WidgetFileSelector(theParent, workshop(), theWidgetApi, theParentId);
- }
+ } else if (theType == "sketch_launcher") {
+ aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
+ }
return aWgt;
}
/// \param theObjectBrowser a pinter on Object Browser widget
virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
+ /// Sends the operation for launching
+ /// \param theOperation the operation
+ virtual void sendOperation(ModuleBase_Operation* theOperation);
+
public slots:
/// SLOT, that is called by no more widget signal emitted by property panel
/// Set a specific flag to restart the sketcher operation
/// Register properties of this module
virtual void registerProperties();
- /// Sends the operation for launching
- /// \param theOperation the operation
- virtual void sendOperation(ModuleBase_Operation* theOperation);
-
private slots:
/// Processing of vertex selected
void onVertexSelected();
if (theOperation->isEditOperation()) {
// If it is editing of sketch then it means that plane is already defined
std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
- myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
+ if (aPln.get())
+ myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
}
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
// all sketch objects should be activated in the sketch selection modes by edit operation start
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: PartSet_WidgetSketchCreator.cpp
+// Created: 08 June 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "PartSet_WidgetSketchCreator.h"
+#include "PartSet_Module.h"
+
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_SelectionMgr.h>
+
+#include <GeomAPI_Face.h>
+
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_Operation.h>
+#include <ModuleBase_IPropertyPanel.h>
+#include <Config_WidgetAPI.h>
+
+#include <QLabel>
+#include <QLineEdit>
+#include <QFormLayout>
+
+PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
+ PartSet_Module* theModule,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+: ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule)
+{
+ QFormLayout* aLayout = new QFormLayout(this);
+ ModuleBase_Tools::adjustMargins(aLayout);
+
+ QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+ myLabel = new QLabel(aLabelText, this);
+ if (!aLabelIcon.isEmpty())
+ myLabel->setPixmap(QPixmap(aLabelIcon));
+
+
+ QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+ myTextLine = new QLineEdit(this);
+ myTextLine->setReadOnly(true);
+ myTextLine->setToolTip(aToolTip);
+ myTextLine->installEventFilter(this);
+
+ aLayout->addRow(myLabel, myTextLine);
+}
+
+PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator()
+{
+}
+
+QList<QWidget*> PartSet_WidgetSketchCreator::getControls() const
+{
+ QList<QWidget*> aControls;
+ aControls.append(myTextLine);
+ return aControls;
+}
+
+bool PartSet_WidgetSketchCreator::restoreValue()
+{
+ return true;
+}
+
+bool PartSet_WidgetSketchCreator::storeValueCustom() const
+{
+ return true;
+}
+
+void PartSet_WidgetSketchCreator::activateCustom()
+{
+ connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+
+
+ //XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+ //XGUI_Workshop* aWorkshop = aConnector->workshop();
+ //XGUI_Displayer* aDisp = aWorkshop->displayer();
+
+ //QIntList aModes;
+ //aModes << TopAbs_FACE;
+ //aDisp->activateObjects(aModes);
+ //
+ //connect(aWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ //activateFilters(myModule->workshop(), true);
+}
+
+void PartSet_WidgetSketchCreator::onStarted()
+{
+ disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
+
+ CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+ FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
+
+ ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
+ anOperation->setFeature(aSketch);
+ myModule->sendOperation(anOperation);
+}
+
+void PartSet_WidgetSketchCreator::storeAttributeValue()
+{
+}
+
+void PartSet_WidgetSketchCreator::restoreAttributeValue(const bool theValid)
+{
+}
+
+bool PartSet_WidgetSketchCreator::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face());
+ aFace->setImpl(new TopoDS_Shape(thePrs.shape()));
+ if (aFace->isPlanar())
+ return true;
+ //CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+ //FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
+
+ //ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
+ //anOperation->setFeature(aSketch);
+ //myModule->sendOperation(anOperation);
+ return false;
+}
+
+bool PartSet_WidgetSketchCreator::setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition)
+{
+ return true;
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: PartSet_WidgetSketchCreator.h
+// Created: 08 June 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef PartSet_WidgetSketchCreator_H
+#define PartSet_WidgetSketchCreator_H
+
+#include "PartSet.h"
+
+#include <ModuleBase_ModelWidget.h>
+
+class QLabel;
+class QLineEdit;
+class PartSet_Module;
+class ModuleBase_Operation;
+
+class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_ModelWidget
+{
+Q_OBJECT
+ public:
+ /// Constructor
+ /// \param theParent the parent object
+ /// \param theData the widget configuation. The attribute of the model widget is obtained from
+ /// \param theParentId is Id of a parent of the current attribute
+ PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule,
+ const Config_WidgetAPI* theData, const std::string& theParentId);
+
+ virtual ~PartSet_WidgetSketchCreator();
+
+ /// Set the given wrapped value to the current widget
+ /// This value should be processed in the widget according to the needs
+ /// The method is called by the current operation to process the operation preselection.
+ /// It is redefined to do nothing if the plane of the sketch has been already set.
+ /// \param theValues the wrapped selection values
+ /// \param thePosition an index in the list of values, the values should be get from the index
+ virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
+
+ virtual bool restoreValue();
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+protected:
+ /// 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
+ virtual void restoreAttributeValue(const bool theValid);
+
+ /// Fills the attribute with the value of the selected owner
+ /// \param theOwner a selected owner
+ virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
+ /// Saves the internal parameters to the given feature
+ /// \return True in success
+ virtual bool storeValueCustom() const;
+
+ /// The methiod called when widget is activated
+ virtual void activateCustom();
+
+private slots:
+ void onStarted();
+
+private:
+
+ PartSet_Module* myModule;
+
+ /// Label of the widget
+ QLabel* myLabel;
+
+ /// Input control of the widget
+ QLineEdit* myTextLine;
+
+};
+
+#endif
\ No newline at end of file
{
if (theShape.IsNull())
return std::shared_ptr<GeomAPI_Dir>();
-
+ int aType = theShape.ShapeType();
// get selected shape
std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
aGShape->setImpl(new TopoDS_Shape(theShape));
+
+
// get plane parameters
std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
if (theFeature->isAction() || !theFeature->data())
return;
foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
- eachWidget->setFeature(theFeature);
+ if (!eachWidget->feature().get())
+ eachWidget->setFeature(theFeature);
eachWidget->restoreValue();
}
// the repaint is used here to immediately react in GUI to the values change.
}
//******************************************************
-void XGUI_Workshop::onFeatureTriggered()
-{
- QAction* aCmd = dynamic_cast<QAction*>(sender());
- if (aCmd) {
- QString aId = salomeConnector()->commandId(aCmd);
- if (!aId.isNull())
- myModule->launchOperation(aId);
- }
-}
+//void XGUI_Workshop::onFeatureTriggered()
+//{
+// QAction* aCmd = dynamic_cast<QAction*>(sender());
+// if (aCmd) {
+// QString aId = salomeConnector()->commandId(aCmd);
+// if (!aId.isNull())
+// myModule->launchOperation(aId);
+// }
+//}
//******************************************************
void XGUI_Workshop::salomeViewerSelectionChanged()
//! Signal to update Undo history list
void updateUndoHistory(const QList<ActionInfo>&);
+
//! Signal to update Redo history list
void updateRedoHistory(const QList<ActionInfo>&);
void hideObjectBrowser();
/// Reaction on command call
- void onFeatureTriggered();
+ //void onFeatureTriggered();
/// Close document
void closeDocument();