From ea948b36a6cc9163da5d2324b04572c9dddd5fd5 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 3 Sep 2014 19:02:10 +0400 Subject: [PATCH] Boolean operations created --- src/Config/CMakeLists.txt | 4 ++- src/Config/Config_PropManager.h | 22 ++++++------ src/Events/Events_Loop.cpp | 4 +++ src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp | 21 +++++++++-- src/FeaturesPlugin/FeaturesPlugin_Boolean.h | 5 +++ src/FeaturesPlugin/boolean_widget.xml | 9 +++-- src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp | 36 +++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h | 17 ++++++++- src/ModelAPI/ModelAPI_Feature.cpp | 2 +- src/ModuleBase/ModuleBase_WidgetChoice.cpp | 25 +++++++++++-- src/ModuleBase/ModuleBase_WidgetFactory.cpp | 19 ++++++++++ src/ModuleBase/ModuleBase_WidgetFactory.h | 1 + src/ModuleBase/ModuleBase_WidgetFeature.cpp | 5 +-- src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 2 ++ src/ModuleBase/ModuleBase_WidgetSelector.cpp | 24 ++++++------- src/ModuleBase/ModuleBase_WidgetSelector.h | 11 ------ src/XGUI/XGUI_ViewWindow.cpp | 8 +++++ 17 files changed, 167 insertions(+), 48 deletions(-) diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index 1b52cfbb8..c40289ab9 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -43,7 +43,9 @@ SET(PROJECT_LIBRARIES SOURCE_GROUP ("Resource Files" FILES ${XML_RESOURCES}) -ADD_DEFINITIONS(-DCONFIG_EXPORTS) +ADD_DEFINITIONS(-DCONFIG_EXPORTS -D_SCL_SECURE_NO_WARNINGS) +# -D_SCL_SECURE_NO_WARNINGS - to disable warnings 4996 + ADD_LIBRARY(Config SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES}) TARGET_LINK_LIBRARIES(Config ${PROJECT_LIBRARIES}) diff --git a/src/Config/Config_PropManager.h b/src/Config/Config_PropManager.h index 8f36c3500..eae15b1c3 100644 --- a/src/Config/Config_PropManager.h +++ b/src/Config/Config_PropManager.h @@ -13,7 +13,7 @@ #include //! Class wihich let to register properties -class CONFIG_EXPORT Config_PropManager +class Config_PropManager { public: @@ -26,32 +26,32 @@ class CONFIG_EXPORT Config_PropManager * \param theValue - initial value of the property * Returns True if the property succesfully registered */ - static bool registerProp(const std::string& theSection, const std::string& theName, + CONFIG_EXPORT static bool registerProp(const std::string& theSection, const std::string& theName, const std::string& theTitle, Config_Prop::PropType theType, const std::string& theValue); - static Config_Prop* findProp(const std::string& theSection, const std::string& theName); + CONFIG_EXPORT static Config_Prop* findProp(const std::string& theSection, const std::string& theName); - static Config_Properties getProperties(); + CONFIG_EXPORT static Config_Properties getProperties(); //! Returns list of registered section names. - static std::list getSections(); + CONFIG_EXPORT static std::list getSections(); //! Returns list of properties by its owner and section. - static Config_Properties getProperties(const std::string& theSection); + CONFIG_EXPORT static Config_Properties getProperties(const std::string& theSection); //! Returns value of the property by its owner, section, and name - static std::string string(const std::string& theSection, const std::string& theName, + CONFIG_EXPORT static std::string string(const std::string& theSection, const std::string& theName, const std::string& theDefault); - static std::vector color(const std::string& theSection, const std::string& theName, + CONFIG_EXPORT static std::vector color(const std::string& theSection, const std::string& theName, const std::string& theDefault); - static int integer(const std::string& theSection, const std::string& theName, + CONFIG_EXPORT static int integer(const std::string& theSection, const std::string& theName, const std::string& theDefault); - static double real(const std::string& theSection, const std::string& theName, + CONFIG_EXPORT static double real(const std::string& theSection, const std::string& theName, const std::string& theDefault); private: - static Config_Properties myProps; + CONFIG_EXPORT static Config_Properties myProps; }; #endif diff --git a/src/Events/Events_Loop.cpp b/src/Events/Events_Loop.cpp index c8cf0e86e..80f48ef48 100644 --- a/src/Events/Events_Loop.cpp +++ b/src/Events/Events_Loop.cpp @@ -25,7 +25,11 @@ Events_ID Events_Loop::eventByName(const char* theName) string aName(theName); map::iterator aFound = CREATED_EVENTS.find(aName); if (aFound == CREATED_EVENTS.end()) { //not created yet +#ifdef WIN32 + aResult = _strdup(theName); // copy to make unique internal pointer +#else aResult = strdup(theName); // copy to make unique internal pointer +#endif CREATED_EVENTS[aName] = aResult; } else aResult = aFound->second; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 220b4144c..3161b31c2 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -18,7 +19,7 @@ FeaturesPlugin_Boolean::FeaturesPlugin_Boolean() void FeaturesPlugin_Boolean::initAttributes() { - data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeReference::type()); + data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::type()); data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::type()); data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::type()); } @@ -39,6 +40,12 @@ boost::shared_ptr FeaturesPlugin_Boolean::getShape(const std::str void FeaturesPlugin_Boolean::execute() { + boost::shared_ptr aTypeAttr = boost::dynamic_pointer_cast< + ModelAPI_AttributeInteger>(data()->attribute(FeaturesPlugin_Boolean::TYPE_ID())); + if (!aTypeAttr) + return; + int aType = aTypeAttr->value(); + boost::shared_ptr aObject = this->getShape(FeaturesPlugin_Boolean::OBJECT_ID()); if (!aObject) return; @@ -48,6 +55,16 @@ void FeaturesPlugin_Boolean::execute() return; boost::shared_ptr aResult = document()->createBody(data()); - aResult->store(GeomAlgoAPI_Boolean::makeCut(aObject, aTool)); + switch (aType) { + case BOOL_CUT: + aResult->store(GeomAlgoAPI_Boolean::makeCut(aObject, aTool)); + break; + case BOOL_FUSE: + aResult->store(GeomAlgoAPI_Boolean::makeFuse(aObject, aTool)); + break; + case BOOL_COMMON: + aResult->store(GeomAlgoAPI_Boolean::makeCommon(aObject, aTool)); + break; + } setResult(aResult); } \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h index d4b0e22cf..159163565 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h @@ -37,6 +37,11 @@ class FeaturesPlugin_Boolean : public ModelAPI_Feature return MY_TOOL_ID; } + enum { + BOOL_CUT, + BOOL_FUSE, + BOOL_COMMON + }; /// Returns the kind of a feature diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml index d0ee131a4..c80856f29 100644 --- a/src/FeaturesPlugin/boolean_widget.xml +++ b/src/FeaturesPlugin/boolean_widget.xml @@ -3,14 +3,17 @@ label="Main object" icon=":icons/cut_shape.png" tooltip="Select an object to cut" - activate="true" - shape_types="solid,shell" + shape_types="solid shell" /> + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp index 0f68186e4..d56a226aa 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp @@ -5,6 +5,8 @@ #include "GeomAlgoAPI_Boolean.h" #include +#include +#include boost::shared_ptr GeomAlgoAPI_Boolean::makeCut( @@ -22,3 +24,37 @@ boost::shared_ptr GeomAlgoAPI_Boolean::makeCut( } return boost::shared_ptr(); } + + +boost::shared_ptr GeomAlgoAPI_Boolean::makeFuse( + boost::shared_ptr theShape, + boost::shared_ptr theTool) +{ + const TopoDS_Shape& aShape = theShape->impl(); + const TopoDS_Shape& aTool = theTool->impl(); + + BRepAlgoAPI_Fuse aFuse(aShape, aTool); + if (aFuse.IsDone()) { + boost::shared_ptr aResult(new GeomAPI_Shape()); + aResult->setImpl(new TopoDS_Shape(aFuse.Shape())); + return aResult; + } + return boost::shared_ptr(); +} + + +boost::shared_ptr GeomAlgoAPI_Boolean::makeCommon( + boost::shared_ptr theShape, + boost::shared_ptr theTool) +{ + const TopoDS_Shape& aShape = theShape->impl(); + const TopoDS_Shape& aTool = theTool->impl(); + + BRepAlgoAPI_Common aCommon(aShape, aTool); + if (aCommon.IsDone()) { + boost::shared_ptr aResult(new GeomAPI_Shape()); + aResult->setImpl(new TopoDS_Shape(aCommon.Shape())); + return aResult; + } + return boost::shared_ptr(); +} \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h index 790e7950c..6a8f9c657 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Boolean.h @@ -17,13 +17,28 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_Boolean { public: /* \brief Creates cut boolean operation - * \param[in] theShape face or wire to be extruded + * \param[in] theShape the main shape * \param[in] theTool toole shape for boolean * \return a solid as result of operation */ static boost::shared_ptr makeCut(boost::shared_ptr theShape, boost::shared_ptr theTool); + /* \brief Creates fuse boolean operation + * \param[in] theShape the main shape + * \param[in] theTool second shape + * \return a solid as result of operation + */ + static boost::shared_ptr makeFuse(boost::shared_ptr theShape, + boost::shared_ptr theTool); + + /* \brief Creates common boolean operation + * \param[in] theShape the main shape + * \param[in] theTool second shape + * \return a solid as result of operation + */ + static boost::shared_ptr makeCommon(boost::shared_ptr theShape, + boost::shared_ptr theTool); }; #endif diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 18ca3f550..158675e9f 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -50,7 +50,7 @@ void ModelAPI_Feature::setResult(const boost::shared_ptr& theRe static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent); // Create event for first Feature, send it to make "created" earlier than "updated" - Events_Loop::loop()->flush(anEvent); + //Events_Loop::loop()->flush(anEvent); } else { // update *aResIter = theResult; static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index 6a1c455d9..ba5a281ed 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -4,6 +4,8 @@ #include "ModuleBase_WidgetChoice.h" +#include +#include #include #include @@ -23,11 +25,17 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); myLabel = new QLabel(aLabelText, myContainer); - myLabel->setPixmap(QPixmap(aLabelIcon)); + if (!aLabelIcon.isEmpty()) + myLabel->setPixmap(QPixmap(aLabelIcon)); aLayout->addWidget(myLabel); myCombo = new QComboBox(myContainer); - aLayout->addWidget(myCombo); + aLayout->addWidget(myCombo, 1); + + std::string aTypes = theData->getProperty("string_list"); + QStringList aList = QString(aTypes.c_str()).split(' '); + myCombo->addItems(aList); + connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); } @@ -37,11 +45,22 @@ ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice() bool ModuleBase_WidgetChoice::storeValue() const { + DataPtr aData = myFeature->data(); + boost::shared_ptr aIntAttr = aData->integer(attributeID()); + + aIntAttr->setValue(myCombo->currentIndex()); + updateObject(myFeature); return true; } bool ModuleBase_WidgetChoice::restoreValue() { + DataPtr aData = myFeature->data(); + boost::shared_ptr aIntAttr = aData->integer(attributeID()); + + bool isBlocked = myCombo->blockSignals(true); + myCombo->setCurrentIndex(aIntAttr->value()); + myCombo->blockSignals(isBlocked); return true; } @@ -61,4 +80,6 @@ QList ModuleBase_WidgetChoice::getControls() const void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex) { + emit valuesChanged(); + emit focusOutWidget(this); } \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 46b7e03d0..cbe5a9939 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -142,10 +143,18 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType } else if (theType == WDG_DOUBLEVALUE_EDITOR) { result = doubleValueEditor(theParent); + } else if (theType == WDG_DOUBLEVALUE_EDITOR) { + result = doubleValueEditor(theParent); + } else if (theType == WDG_POINT2D_DISTANCE) { result = point2dDistanceControl(theParent); + } else if (theType == WDG_FILE_SELECTOR) { result = fileSelectorControl(theParent); + + } else if (theType == WDG_CHOICE) { + result = choiceControl(theParent); + } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { result = createContainer(theType, theParent); } else { @@ -270,3 +279,13 @@ QWidget* ModuleBase_WidgetFactory::fileSelectorControl(QWidget* theParent) return aFileSelectorWgt->getControl(); } + +QWidget* ModuleBase_WidgetFactory::choiceControl(QWidget* theParent) +{ + ModuleBase_WidgetChoice* aChoiceWgt = new ModuleBase_WidgetChoice(theParent, myWidgetApi, + myParentId); + myModelWidgets.append(aChoiceWgt); + + return aChoiceWgt->getControl(); +} + diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index 643e85b67..1b9e031bf 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -47,6 +47,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory QWidget* booleanControl(QWidget* theParent); QWidget* point2dDistanceControl(QWidget* theParent); QWidget* fileSelectorControl(QWidget* theParent); + QWidget* choiceControl(QWidget* theParent); /// Check whether the XML definition for the given type contains internal property /// \param theType the widget type diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp index dd8fb9493..08cb49f00 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -117,8 +117,9 @@ bool ModuleBase_WidgetFeature::setObject(const ObjectPtr& theObject, bool theSen bool ModuleBase_WidgetFeature::storeValue() const { //FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); - //if (!aFeature) - // return false; + if (!myObject) + return false; + boost::shared_ptr aData = myFeature->data(); boost::shared_ptr aRef = boost::dynamic_pointer_cast< ModelAPI_AttributeRefAttr>(aData->attribute(attributeID())); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 5e447ef1d..157ccb45d 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -110,6 +110,8 @@ bool ModuleBase_WidgetPoint2D::storeValue() const ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this; bool isBlocked = that->blockSignals(true); + double aX = myXSpin->value(); + double aY = myYSpin->value(); aPoint->setValue(myXSpin->value(), myYSpin->value()); updateObject(myFeature); that->blockSignals(isBlocked); diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 35cb90e18..8f0c1324f 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -54,8 +54,7 @@ ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) : ModuleBase_ModelWidget(theParent, theData, theParentId), - myWorkshop(theWorkshop), - myActivateOnStart(false) + myWorkshop(theWorkshop) { myContainer = new QWidget(theParent); QHBoxLayout* aLayout = new QHBoxLayout(myContainer); @@ -64,7 +63,8 @@ ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); myLabel = new QLabel(aLabelText, myContainer); - myLabel->setPixmap(QPixmap(aLabelIcon)); + if (!aLabelIcon.isEmpty()) + myLabel->setPixmap(QPixmap(aLabelIcon)); aLayout->addWidget(myLabel); @@ -77,8 +77,9 @@ ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, myBasePalet = myTextLine->palette(); myInactivePalet = myBasePalet; myInactivePalet.setBrush(QPalette::Base, QBrush(Qt::gray, Qt::Dense6Pattern)); + myTextLine->setPalette(myInactivePalet); - aLayout->addWidget(myTextLine); + aLayout->addWidget(myTextLine, 1); myActivateBtn = new QToolButton(myContainer); myActivateBtn->setIcon(QIcon(":icons/hand_point.png")); @@ -88,13 +89,8 @@ ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, aLayout->addWidget(myActivateBtn); - QString aActivateTxt = QString::fromStdString(theData->getProperty("activate")); - if (!aActivateTxt.isNull()) { - myActivateOnStart = (aActivateTxt == "true"); - } - std::string aTypes = theData->getProperty("shape_types"); - myShapeTypes = QString(aTypes.c_str()).split(','); + myShapeTypes = QString(aTypes.c_str()).split(' '); } //******************************************************************** @@ -215,10 +211,10 @@ void ModuleBase_WidgetSelector::updateSelectionName() bool ModuleBase_WidgetSelector::eventFilter(QObject* theObj, QEvent* theEvent) { if (theObj == myTextLine) { - if (theEvent->type() == QEvent::Polish) { - myActivateBtn->setChecked(myActivateOnStart); - onSelectionChanged(); - } + //if (theEvent->type() == QEvent::Polish) { + // myActivateBtn->setChecked(myActivateOnStart); + // onSelectionChanged(); + //} } return ModuleBase_ModelWidget::eventFilter(theObj, theEvent); } diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 0eba6cdee..5973c520a 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -50,15 +50,6 @@ Q_OBJECT /// \return a control list virtual QList getControls() const; - void setActivationOnStart(bool toActivate) - { - myActivateOnStart = toActivate; - } - bool activateOnStart() const - { - return myActivateOnStart; - } - ObjectPtr selectedFeature() const { return mySelectedObject; @@ -90,8 +81,6 @@ Q_OBJECT ModuleBase_IWorkshop* myWorkshop; - bool myActivateOnStart; - ObjectPtr mySelectedObject; QStringList myShapeTypes; diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index 69e4f2a4a..b9c346009 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -1055,9 +1055,17 @@ void XGUI_ViewWindow::dumpView() Handle(Visual3d_View) a3dView = myViewPort->getView()->View(); if (aFmt == "PS") +#ifdef WIN32 + a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript); +#else a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_PostScript); +#endif else if (aFmt == "EPS") +#ifdef WIN32 + a3dView->Export(_strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript); +#else a3dView->Export(strdup(qPrintable(aFileName)), Graphic3d_EF_EnhPostScript); +#endif else aPicture.save(aFileName, aFmt.toLatin1()); QApplication::restoreOverrideCursor(); -- 2.39.2