+ fix crash on abort of adding primitives

This commit is contained in:
wmayer 2016-04-24 14:17:01 +02:00
parent b08a75bfb2
commit 6b4821a855
4 changed files with 63 additions and 38 deletions

View File

@ -29,6 +29,7 @@
# include <QTextStream> # include <QTextStream>
# include <QMessageBox> # include <QMessageBox>
# include <Precision.hxx> # include <Precision.hxx>
# include <boost/bind.hpp>
#endif #endif
#include <Base/Console.h> #include <Base/Console.h>
@ -214,8 +215,8 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p
updateListOfModes(eMapMode(pcDatum->MapMode.getValue())); updateListOfModes(eMapMode(pcDatum->MapMode.getValue()));
//temporary show coordinate systems for selection //temporary show coordinate systems for selection
PartDesign::Body * body = PartDesign::Body::findBodyOf ( DatumView->getObject() ); PartDesign::Body * body = PartDesign::Body::findBodyOf(DatumView->getObject());
if(body) { if (body) {
try { try {
App::Origin *origin = body->getOrigin(); App::Origin *origin = body->getOrigin();
ViewProviderOrigin* vpOrigin; ViewProviderOrigin* vpOrigin;
@ -225,14 +226,52 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p
Base::Console().Error ("%s\n", ex.what () ); Base::Console().Error ("%s\n", ex.what () );
} }
} }
if (pcDatum->Support.getSize() == 0) if (pcDatum->Support.getSize() == 0)
autoNext = true; autoNext = true;
else else
autoNext = false; autoNext = false;
DatumView->setPickable(false); DatumView->setPickable(false);
// connect object deletion with slot
auto bnd = boost::bind(&TaskDatumParameters::objectDeleted, this, _1);
Gui::Document* document = Gui::Application::Instance->getDocument(DatumView->getObject()->getDocument());
connectDelObject = document->signalDeletedObject.connect(bnd);
} }
TaskDatumParameters::~TaskDatumParameters()
{
connectDelObject.disconnect();
if (DatumView)
resetViewMode();
delete ui;
}
void TaskDatumParameters::resetViewMode()
{
//end temporary view mode of coordinate system
PartDesign::Body * body = PartDesign::Body::findBodyOf(DatumView->getObject());
if (body) {
try {
App::Origin *origin = body->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
}
catch (const Base::Exception &ex) {
Base::Console().Error("%s\n", ex.what());
}
}
DatumView->setPickable(true);
}
void TaskDatumParameters::objectDeleted(const Gui::ViewProviderDocumentObject& view)
{
if (DatumView == &view)
DatumView = nullptr;
}
const QString makeHintText(std::set<eRefType> hint) const QString makeHintText(std::set<eRefType> hint)
{ {
@ -737,26 +776,6 @@ bool TaskDatumParameters::getFlip() const
return ui->checkBoxFlip->isChecked(); return ui->checkBoxFlip->isChecked();
} }
TaskDatumParameters::~TaskDatumParameters()
{
//end temporary view mode of coordinate system
PartDesign::Body * body = PartDesign::Body::findBodyOf ( DatumView->getObject() );
if(body) {
try {
App::Origin *origin = body->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
DatumView->setPickable(true);
delete ui;
}
void TaskDatumParameters::changeEvent(QEvent *e) void TaskDatumParameters::changeEvent(QEvent *e)
{ {
TaskBox::changeEvent(e); TaskBox::changeEvent(e);

View File

@ -89,6 +89,8 @@ protected:
void changeEvent(QEvent *e); void changeEvent(QEvent *e);
private: private:
void resetViewMode();
void objectDeleted(const Gui::ViewProviderDocumentObject&);
void onSelectionChanged(const Gui::SelectionChanges& msg); void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI(std::string message = std::string(), bool isWarning = false); void updateUI(std::string message = std::string(), bool isWarning = false);
@ -117,6 +119,8 @@ private:
std::vector<Attacher::eMapMode> modesInList; //this list is synchronous to what is populated into listOfModes widget. std::vector<Attacher::eMapMode> modesInList; //this list is synchronous to what is populated into listOfModes widget.
bool completed; bool completed;
typedef boost::BOOST_SIGNALS_NAMESPACE::connection Connection;
Connection connectDelObject;
}; };
/// simulation dialog for the TaskView /// simulation dialog for the TaskView

View File

@ -29,7 +29,7 @@
# include <QTextStream> # include <QTextStream>
# include <QMessageBox> # include <QMessageBox>
# include <Precision.hxx> # include <Precision.hxx>
#include <boost/bind/bind.hpp> # include <boost/bind/bind.hpp>
#endif #endif
#include "TaskPrimitiveParameters.h" #include "TaskPrimitiveParameters.h"
@ -624,10 +624,10 @@ TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* Primitiv
parameter = new TaskDatumParameters(vp); parameter = new TaskDatumParameters(vp);
Content.push_back(parameter); Content.push_back(parameter);
primitive = new TaskBoxPrimitives(PrimitiveView); primitive = new TaskBoxPrimitives(PrimitiveView);
Content.push_back(primitive); Content.push_back(primitive);
//make sure we track changes from the coordinate system to the primitive position //make sure we track changes from the coordinate system to the primitive position
auto bnd = boost::bind(&TaskPrimitiveParameters::objectChanged, this, _1, _2); auto bnd = boost::bind(&TaskPrimitiveParameters::objectChanged, this, _1, _2);
connection = vp_prm->getObject()->getDocument()->signalChangedObject.connect(bnd); connection = vp_prm->getObject()->getDocument()->signalChangedObject.connect(bnd);
@ -656,25 +656,27 @@ bool TaskPrimitiveParameters::accept()
ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>( ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>(
Gui::Application::Instance->activeDocument()->getViewProvider(cs)); Gui::Application::Instance->activeDocument()->getViewProvider(cs));
vp->setVisible(cs_visibility); vp->setVisible(cs_visibility);
connection.disconnect(); connection.disconnect();
return true; return true;
} }
bool TaskPrimitiveParameters::reject() { bool TaskPrimitiveParameters::reject()
{
// roll back the done things // roll back the done things
Gui::Command::abortCommand(); Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
//if we did not delete the document object we need to set the visibilities right //if we did not delete the document object we need to set the visibilities right
ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>( ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>(
Gui::Application::Instance->activeDocument()->getViewProvider(cs)); Gui::Application::Instance->activeDocument()->getViewProvider(cs));
if(vp) if (vp)
vp->setVisible(cs_visibility); vp->setVisible(cs_visibility);
connection.disconnect(); connection.disconnect();
return true; return true;
} }

View File

@ -58,7 +58,7 @@ public:
~TaskBoxPrimitives(); ~TaskBoxPrimitives();
void setPrimitive(QString name); void setPrimitive(QString name);
public Q_SLOTS: public Q_SLOTS:
void onBoxLengthChanged(double); void onBoxLengthChanged(double);
void onBoxWidthChanged(double); void onBoxWidthChanged(double);
@ -120,8 +120,8 @@ protected:
virtual bool accept(); virtual bool accept();
virtual bool reject(); virtual bool reject();
private: private:
s::connection connection; s::connection connection;
TaskBoxPrimitives* primitive; TaskBoxPrimitives* primitive;
TaskDatumParameters* parameter; TaskDatumParameters* parameter;