In additional isModelObject() method is added.
The bug functionality is in Module::edit(). The feature is obtained from the model object if it is.
bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- if (!aData) {
- ObjectPtr anObj = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
- if (anObj) aData = anObj->featureRef()->data();
- }
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- if (!aData) {
- ObjectPtr anObj = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
- if (anObj) aData = anObj->featureRef()->data();
- }
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
#include <PartSet_TestOCC.h>
#include <ModuleBase_Operation.h>
+#include <ModelAPI_Object.h>
#include <XGUI_MainWindow.h>
#include <XGUI_Displayer.h>
#include <XGUI_ViewerProxy.h>
#include <XGUI_ContextMenuMgr.h>
#include <XGUI_PropertyPanel.h>
+#include <XGUI_Tools.h>
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
return;
if (theFeature->getKind() == "Sketch") {
- onLaunchOperation(theFeature->getKind(), theFeature);
- updateCurrentPreview(theFeature->getKind());
+ FeaturePtr aFeature = theFeature;
+ if (XGUI_Tools::isModelObject(aFeature)) {
+ ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
+ aFeature = aObject->featureRef();
+ }
+
+ if (aFeature) {
+ onLaunchOperation(aFeature->getKind(), aFeature);
+ updateCurrentPreview(aFeature->getKind());
+ }
}
}
#include <PartSet_OperationSketchBase.h>
#include <SketchPlugin_Feature.h>
-#include <ModelAPI_Object.h>
#include <V3d_View.hxx>
{
boost::shared_ptr<SketchPlugin_Feature> aFeature =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
- if (!aFeature) { // if it is reference to a object feature
- boost::shared_ptr<ModelAPI_Object> anObj =
- boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
- if (anObj)
- aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(anObj->featureRef());
- }
if (!aFeature)
return boost::shared_ptr<GeomAPI_Shape>();
return aFeature->preview();
#include "XGUI_DocumentDataModel.h"
#include "XGUI_PartDataModel.h"
#include "XGUI_Workshop.h"
+#include "XGUI_Tools.h"
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const
{
FeaturePtr aFeature = theFeature;
- if (!aFeature->data()) {
+ if (XGUI_Tools::isModelObject(aFeature)) {
ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
aFeature = aObject->featureRef();
}
#include "XGUI_ObjectsBrowser.h"
#include "XGUI_DocumentDataModel.h"
+#include "XGUI_Tools.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_PluginManager.h>
FeaturePtr aFeature = mySelectedData.first();
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
aMgr->rootDocument()->startOperation();
- if (aFeature->data())
+ if (!XGUI_Tools::isModelObject(aFeature))
aFeature->data()->setName(qPrintable(aRes));
else
boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->setName(qPrintable(aRes));
#include <iostream>
#include <sstream>
+namespace XGUI_Tools
+{
//******************************************************************
QString dir(const QString& path, bool isAbs)
{
return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1));
}
+//******************************************************************
+bool isModelObject(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ return theFeature && !theFeature->data();
+}
+
//******************************************************************
std::string featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature)
{
return QString(aStream.str().c_str()).toStdString();
}
+}
\ No newline at end of file
\param abs if true (default) \a path parameter is treated as absolute file path
\return directory part of the file path
*/
-QString XGUI_EXPORT dir(const QString& path, bool isAbs = true);
+namespace XGUI_Tools
+{
+ QString XGUI_EXPORT dir(const QString& path, bool isAbs = true);
-/*!
- \brief Return file name part of the file path.
+ /*!
+ \brief Return file name part of the file path.
- \param path file path
- \param withExt if true (default) complete file name (with all
- extension except the last) is returned, otherwise only base name
- is returned
- \return file name part of the file path
- */
-QString XGUI_EXPORT file(const QString& path, bool withExt = true);
+ \param path file path
+ \param withExt if true (default) complete file name (with all
+ extension except the last) is returned, otherwise only base name
+ is returned
+ \return file name part of the file path
+ */
+ QString XGUI_EXPORT file(const QString& path, bool withExt = true);
-/*!
- \brief Return extension part of the file path.
+ /*!
+ \brief Return extension part of the file path.
- \param path file path
- \param full if true complete extension (all extensions, dot separated)
- is returned, otherwise (default) only last extension is returned
- \return extension part of the file path
- */
-QString XGUI_EXPORT extension(const QString& path, bool full = false);
+ \param path file path
+ \param full if true complete extension (all extensions, dot separated)
+ is returned, otherwise (default) only last extension is returned
+ \return extension part of the file path
+ */
+ QString XGUI_EXPORT extension(const QString& path, bool full = false);
-/*!
- \brief Add a slash (platform-specific) to the end of \a path
- if it is not already there.
- \param path directory path
- \return modified path (with slash added to the end)
- */
-QString XGUI_EXPORT addSlash(const QString& path);
+ /*!
+ \brief Add a slash (platform-specific) to the end of \a path
+ if it is not already there.
+ \param path directory path
+ \return modified path (with slash added to the end)
+ */
+ QString XGUI_EXPORT addSlash(const QString& path);
-/*!
- Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) )
- and BottomRight = ( TopLeft + (x2-x1)(y2-y1) )
- */
-QRect XGUI_EXPORT makeRect(const int x1, const int y1, const int x2, const int y2);
+ /*!
+ Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) )
+ and BottomRight = ( TopLeft + (x2-x1)(y2-y1) )
+ */
+ QRect XGUI_EXPORT makeRect(const int x1, const int y1, const int x2, const int y2);
+
+ /// The model concerning tools
+
+ /*!
+ Returns true if the feature is a model object
+ \param theFeature a feature
+ */
+ bool XGUI_EXPORT isModelObject(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+ /*!
+ Returns the string presentation of the given feature
+ \param theFeature a feature
+ */
+ std::string XGUI_EXPORT featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature);
+}
-/*!
- Returns the string presentation of the given feature
- \param theFeature a feature
-*/
-std::string XGUI_EXPORT featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature);
#endif
myCurrX = theEvent->x();
myCurrY = theEvent->y();
drawRect();
- QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
+ QRect rect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
if (!rect.isEmpty())
myViewPort->fitRect(rect);
endDrawRect();
}
myRectBand->setUpdatesEnabled(false);
- QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
+ QRect aRect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
myRectBand->initGeometry(aRect);
if (!myRectBand->isVisible())
QApplication::setOverrideCursor( Qt::WaitCursor );
QImage aPicture = myViewPort->dumpView();
- QString aFmt = extension(aFileName).toUpper();
+ QString aFmt = XGUI_Tools::extension(aFileName).toUpper();
if( aFmt.isEmpty() )
aFmt = QString( "BMP" ); // default format
else if( aFmt == "JPG" )
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
if (thePart) {
DocumentPtr aFeaDoc;
- if (thePart->data()) {
+ if (!XGUI_Tools::isModelObject(thePart)) {
+ //if (thePart->data()) {
aFeaDoc = thePart->data()->docRef("PartDocument")->value();
} else {
ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(thePart);
foreach (FeaturePtr aFeature, theList) {
if (aFeature->getKind() == "Part") {
DocumentPtr aDoc;
- if (aFeature->data()) {
+ if (!XGUI_Tools::isModelObject(aFeature)) {
+ //if (aFeature->data()) {
aDoc = aFeature->data()->docRef("PartDocument")->value();
} else {
ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
aDoc->close();
}
} else {
- if (!aFeature->data()) {
+ if (XGUI_Tools::isModelObject(aFeature)) {
+ //if (!aFeature->data()) {
ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
aFeature = aObject->featureRef();
}