Skip to content

Commit

Permalink
+ fix crash on abort of adding primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Apr 24, 2016
1 parent b08a75b commit 6b4821a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 38 deletions.
65 changes: 42 additions & 23 deletions src/Mod/PartDesign/Gui/TaskDatumParameters.cpp
Expand Up @@ -29,6 +29,7 @@
# include <QTextStream>
# include <QMessageBox>
# include <Precision.hxx>
# include <boost/bind.hpp>
#endif

#include <Base/Console.h>
Expand Down Expand Up @@ -214,8 +215,8 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p
updateListOfModes(eMapMode(pcDatum->MapMode.getValue()));

//temporary show coordinate systems for selection
PartDesign::Body * body = PartDesign::Body::findBodyOf ( DatumView->getObject() );
if(body) {
PartDesign::Body * body = PartDesign::Body::findBodyOf(DatumView->getObject());
if (body) {
try {
App::Origin *origin = body->getOrigin();
ViewProviderOrigin* vpOrigin;
Expand All @@ -225,14 +226,52 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p
Base::Console().Error ("%s\n", ex.what () );
}
}

if (pcDatum->Support.getSize() == 0)
autoNext = true;
else
autoNext = 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)
{
Expand Down Expand Up @@ -737,26 +776,6 @@ bool TaskDatumParameters::getFlip() const
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)
{
TaskBox::changeEvent(e);
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/PartDesign/Gui/TaskDatumParameters.h
Expand Up @@ -89,6 +89,8 @@ private Q_SLOTS:
void changeEvent(QEvent *e);

private:
void resetViewMode();
void objectDeleted(const Gui::ViewProviderDocumentObject&);
void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI(std::string message = std::string(), bool isWarning = false);

Expand Down Expand Up @@ -117,6 +119,8 @@ private Q_SLOTS:
std::vector<Attacher::eMapMode> modesInList; //this list is synchronous to what is populated into listOfModes widget.
bool completed;

typedef boost::BOOST_SIGNALS_NAMESPACE::connection Connection;
Connection connectDelObject;
};

/// simulation dialog for the TaskView
Expand Down
26 changes: 14 additions & 12 deletions src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp
Expand Up @@ -29,7 +29,7 @@
# include <QTextStream>
# include <QMessageBox>
# include <Precision.hxx>
#include <boost/bind/bind.hpp>
# include <boost/bind/bind.hpp>
#endif

#include "TaskPrimitiveParameters.h"
Expand Down Expand Up @@ -624,10 +624,10 @@ TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* Primitiv

parameter = new TaskDatumParameters(vp);
Content.push_back(parameter);

primitive = new TaskBoxPrimitives(PrimitiveView);
Content.push_back(primitive);

//make sure we track changes from the coordinate system to the primitive position
auto bnd = boost::bind(&TaskPrimitiveParameters::objectChanged, this, _1, _2);
connection = vp_prm->getObject()->getDocument()->signalChangedObject.connect(bnd);
Expand Down Expand Up @@ -656,25 +656,27 @@ bool TaskPrimitiveParameters::accept()
ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>(
Gui::Application::Instance->activeDocument()->getViewProvider(cs));
vp->setVisible(cs_visibility);

connection.disconnect();

connection.disconnect();

return true;
}

bool TaskPrimitiveParameters::reject() {
bool TaskPrimitiveParameters::reject()
{
// roll back the done things
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");

//if we did not delete the document object we need to set the visibilities right
ViewProviderDatumCoordinateSystem* vp = static_cast<ViewProviderDatumCoordinateSystem*>(
Gui::Application::Instance->activeDocument()->getViewProvider(cs));
if(vp)
Gui::Application::Instance->activeDocument()->getViewProvider(cs));

if (vp)
vp->setVisible(cs_visibility);

connection.disconnect();

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Mod/PartDesign/Gui/TaskPrimitiveParameters.h
Expand Up @@ -58,7 +58,7 @@ class TaskBoxPrimitives : public Gui::TaskView::TaskBox
~TaskBoxPrimitives();

void setPrimitive(QString name);

public Q_SLOTS:
void onBoxLengthChanged(double);
void onBoxWidthChanged(double);
Expand Down Expand Up @@ -120,8 +120,8 @@ class TaskPrimitiveParameters : public Gui::TaskView::TaskDialog

virtual bool accept();
virtual bool reject();
private:

private:
s::connection connection;
TaskBoxPrimitives* primitive;
TaskDatumParameters* parameter;
Expand Down

0 comments on commit 6b4821a

Please sign in to comment.