const static char* WDG_SWITCH = "switch";
const static char* WDG_SWITCH_CASE = "case";
const static char* WDG_SELECTOR = "selector";
+const static char* WDG_CHOICE = "choice";
//Specific widget containers
const static char* WDG_POINT_SELECTOR = "point_selector";
FeaturesPlugin.h
FeaturesPlugin_Plugin.h
FeaturesPlugin_Extrusion.h
+ FeaturesPlugin_Boolean.h
)
SET(PROJECT_SOURCES
FeaturesPlugin_Plugin.cpp
FeaturesPlugin_Extrusion.cpp
+ FeaturesPlugin_Boolean.cpp
)
ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
SET(XML_RESOURCES
plugin-Features.xml
extrusion_widget.xml
+ boolean_widget.xml
)
INSTALL(TARGETS FeaturesPlugin DESTINATION plugins)
--- /dev/null
+// File: FeaturesPlugin_Boolean.cpp
+// Created: 02 Sept 2014
+// Author: Vitaly SMETANNIKOV
+
+#include "FeaturesPlugin_Boolean.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_Boolean.h>
+
+using namespace std;
+
+FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
+{
+}
+
+void FeaturesPlugin_Boolean::initAttributes()
+{
+ data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeReference::type());
+ data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::type());
+ data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::type());
+}
+
+boost::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::string& theAttrName)
+{
+ boost::shared_ptr<ModelAPI_AttributeReference> aObjRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeReference>(data()->attribute(theAttrName));
+ if (aObjRef) {
+ boost::shared_ptr<ModelAPI_ResultBody> aConstr = boost::dynamic_pointer_cast<
+ ModelAPI_ResultBody>(aObjRef->value());
+ if (aConstr)
+ return aConstr->shape();
+ }
+ return boost::shared_ptr<GeomAPI_Shape>();
+}
+
+
+void FeaturesPlugin_Boolean::execute()
+{
+ boost::shared_ptr<GeomAPI_Shape> aObject = this->getShape(FeaturesPlugin_Boolean::OBJECT_ID());
+ if (!aObject)
+ return;
+
+ boost::shared_ptr<GeomAPI_Shape> aTool = this->getShape(FeaturesPlugin_Boolean::TOOL_ID());
+ if (!aTool)
+ return;
+
+ boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
+ aResult->store(GeomAlgoAPI_Boolean::makeCut(aObject, aTool));
+ setResult(aResult);
+}
\ No newline at end of file
--- /dev/null
+// File: FeaturesPlugin_Boolean.h
+// Created: 02 Sept 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef FeaturesPlugin_Cut_H_
+#define FeaturesPlugin_Cut_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+#include <GeomAPI_Shape.h>
+
+class FeaturesPlugin_Boolean : public ModelAPI_Feature
+{
+ public:
+ /// Extrusion kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_CUT_ID("Boolean");
+ return MY_CUT_ID;
+ }
+ /// attribute name of referenced object
+ inline static const std::string& OBJECT_ID()
+ {
+ static const std::string MY_OBJECT_ID("main_object");
+ return MY_OBJECT_ID;
+ }
+ /// attribute name of tool object
+ inline static const std::string& TOOL_ID()
+ {
+ static const std::string MY_TOOL_ID("tool_object");
+ return MY_TOOL_ID;
+ }
+ /// attribute name of operation type
+ inline static const std::string& TYPE_ID()
+ {
+ static const std::string MY_TOOL_ID("bool_type");
+ return MY_TOOL_ID;
+ }
+
+
+
+ /// Returns the kind of a feature
+ FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = FeaturesPlugin_Boolean::ID();
+ return MY_KIND;
+ }
+
+ /// Creates a new part document if needed
+ FEATURESPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Use plugin manager for features creation
+ FeaturesPlugin_Boolean();
+
+private:
+ boost::shared_ptr<GeomAPI_Shape> getShape(const std::string& theAttrName);
+
+};
+
+#endif
#include "FeaturesPlugin_Plugin.h"
#include "FeaturesPlugin_Extrusion.h"
+#include "FeaturesPlugin_Boolean.h"
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
{
if (theFeatureID == FeaturesPlugin_Extrusion::ID()) {
return FeaturePtr(new FeaturesPlugin_Extrusion);
+ } else
+ if (theFeatureID == FeaturesPlugin_Boolean::ID()) {
+ return FeaturePtr(new FeaturesPlugin_Boolean);
}
// feature of such kind is not found
return FeaturePtr();
--- /dev/null
+<source>
+ <selector id="main_object"
+ label="Main object"
+ icon=":icons/cut_shape.png"
+ tooltip="Select an object to cut"
+ activate="true"
+ shape_types="solid,shell"
+ />
+ <selector id="tool_object"
+ label="Tool object"
+ icon=":icons/cut_tool.png"
+ tooltip="Select a tool"
+ activate="false"
+ shape_types="solid"
+ />
+</source>
<feature id="Extrusion" title="Extrusion" tooltip="Create a shape by extrusion of a contour" icon=":icons/extrusion.png">
<source path="extrusion_widget.xml"/>
</feature>
+ <feature id="Boolean" title="Boolean" tooltip="Performs boolean operations with shapes" icon=":icons/cut.png">
+ <source path="boolean_widget.xml"/>
+ </feature>
</group>
-</workbench>
+ </workbench>
</plugin>
GeomAlgoAPI_PointBuilder.h
GeomAlgoAPI_SketchBuilder.h
GeomAlgoAPI_Extrusion.h
+ GeomAlgoAPI_Boolean.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_PointBuilder.cpp
GeomAlgoAPI_SketchBuilder.cpp
GeomAlgoAPI_Extrusion.cpp
+ GeomAlgoAPI_Boolean.cpp
)
ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
--- /dev/null
+// File: GeomAlgoAPI_Boolean.cpp
+// Created: 02 Sept 2014
+// Author: Vitaly Smetannikov
+
+#include "GeomAlgoAPI_Boolean.h"
+
+#include <BRepAlgoAPI_Cut.hxx>
+
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeCut(
+ boost::shared_ptr<GeomAPI_Shape> theShape,
+ boost::shared_ptr<GeomAPI_Shape> theTool)
+{
+ const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
+
+ BRepAlgoAPI_Cut aCut(aShape, aTool);
+ if (aCut.IsDone()) {
+ boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
+ aResult->setImpl(new TopoDS_Shape(aCut.Shape()));
+ return aResult;
+ }
+ return boost::shared_ptr<GeomAPI_Shape>();
+}
--- /dev/null
+// File: GeomAlgoAPI_Boolean.h
+// Created: 02 Sept 2014
+// Author: Vitaly Smetannikov
+
+#ifndef GeomAlgoAPI_Boolean_H_
+#define GeomAlgoAPI_Boolean_H_
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+
+/**\class GeomAlgoAPI_Boolean
+ * \ingroup DataAlgo
+ * \brief Allows to perform of boolean operations
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_Boolean
+{
+ public:
+ /* \brief Creates cut boolean operation
+ * \param[in] theShape face or wire to be extruded
+ * \param[in] theTool toole shape for boolean
+ * \return a solid as result of operation
+ */
+ static boost::shared_ptr<GeomAPI_Shape> makeCut(boost::shared_ptr<GeomAPI_Shape> theShape,
+ boost::shared_ptr<GeomAPI_Shape> theTool);
+
+};
+
+#endif
ModuleBase_SelectionValidator.h
ModuleBase_ISelection.h
ModuleBase_ViewerPrs.h
+ ModuleBase_WidgetChoice.h
)
SET(PROJECT_SOURCES
ModuleBase_WidgetPoint2dDistance.cpp
ModuleBase_WidgetValue.cpp
ModuleBase_WidgetValueFeature.cpp
+ ModuleBase_WidgetChoice.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// File: ModuleBase_WidgetChoice.cpp
+// Created: 03 Sept 2014
+// Author: Vitaly Smetannikov
+
+#include "ModuleBase_WidgetChoice.h"
+
+#include <Config_WidgetAPI.h>
+
+#include <QWidget>
+#include <QLayout>
+#include <QLabel>
+#include <QComboBox>
+
+ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+ : ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+ myContainer = new QWidget(theParent);
+ QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
+ aLayout->setContentsMargins(0, 0, 0, 0);
+
+ QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+ myLabel = new QLabel(aLabelText, myContainer);
+ myLabel->setPixmap(QPixmap(aLabelIcon));
+ aLayout->addWidget(myLabel);
+
+ myCombo = new QComboBox(myContainer);
+ aLayout->addWidget(myCombo);
+ connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
+}
+
+ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
+{
+}
+
+bool ModuleBase_WidgetChoice::storeValue() const
+{
+ return true;
+}
+
+bool ModuleBase_WidgetChoice::restoreValue()
+{
+ return true;
+}
+
+bool ModuleBase_WidgetChoice::focusTo()
+{
+ myCombo->setFocus();
+ return true;
+}
+
+QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
+{
+ QList<QWidget*> aControls;
+ aControls.append(myLabel);
+ aControls.append(myCombo);
+ return aControls;
+}
+
+void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
+{
+}
\ No newline at end of file
--- /dev/null
+// File: ModuleBase_WidgetChoice.h
+// Created: 03 Sept 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModuleBase_WidgetChoice_H
+#define ModuleBase_WidgetChoice_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+class QWidget;
+class QLabel;
+class QComboBox;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetChoice : public ModuleBase_ModelWidget
+{
+Q_OBJECT
+ public:
+ ModuleBase_WidgetChoice(QWidget* theParent, const Config_WidgetAPI* theData,
+ const std::string& theParentId);
+
+ virtual ~ModuleBase_WidgetChoice();
+
+ /// Saves the internal parameters to the given feature
+ /// \param theObject a model feature to be changed
+ virtual bool storeValue() const;
+
+ virtual bool restoreValue();
+
+ virtual bool focusTo();
+
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const
+ {
+ return myContainer;
+ }
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+private slots:
+ void onCurrentIndexChanged(int theIndex);
+
+private:
+ QWidget* myContainer;
+ QLabel* myLabel;
+ QComboBox* myCombo;
+};
+
+#endif
myTextLine->setToolTip(aToolTip);
myTextLine->installEventFilter(this);
+ myBasePalet = myTextLine->palette();
+ myInactivePalet = myBasePalet;
+ myInactivePalet.setBrush(QPalette::Base, QBrush(Qt::gray, Qt::Dense6Pattern));
+
aLayout->addWidget(myTextLine);
myActivateBtn = new QToolButton(myContainer);
myTextLine->setText("");
}
emit valuesChanged();
+ emit focusOutWidget(this);
}
}
TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
if (aShapeType == TopAbs_COMPOUND) {
- foreach (QString aType, myShapeTypes)
- {
+ foreach (QString aType, myShapeTypes) {
TopExp_Explorer aEx(aShape, shapeType(aType));
if (aEx.More())
return true;
}
} else {
- foreach (QString aType, myShapeTypes)
- {
+ foreach (QString aType, myShapeTypes) {
if (shapeType(aType) == aShapeType)
return true;
}
void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
{
enableOthersControls(!toActivate);
- myTextLine->setEnabled(toActivate);
+ //myTextLine->setEnabled(toActivate);
+ if (toActivate)
+ myTextLine->setPalette(myBasePalet);
+ else
+ myTextLine->setPalette(myInactivePalet);
if (toActivate)
connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
aTabWgt->raise();
}
}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::focusTo()
+{
+ myActivateBtn->setChecked(true);
+ return true;
+}
#include <TopAbs_ShapeEnum.hxx>
#include <QStringList>
+#include <QPalette>
class Config_WidgetAPI;
class QWidget;
virtual bool restoreValue();
+ virtual bool focusTo();
+
/// Returns the internal parent wiget control, that can be shown anywhere
/// \returns the widget
QWidget* getControl() const
ObjectPtr mySelectedObject;
QStringList myShapeTypes;
+
+ QPalette myBasePalet;
+ QPalette myInactivePalet;
};
#endif
<file>icons/remove.png</file>
<file>icons/extrusion.png</file>
<file>icons/cut.png</file>
+ <file>icons/cut_tool.png</file>
+ <file>icons/cut_shape.png</file>
<file>icons/fusion.png</file>
<file>icons/revol.png</file>
<file>icons/common.png</file>