+ fixes #0000870: Center sketch to a constraint that has been double clicked in the constraint list.

This commit is contained in:
wmayer 2015-09-15 17:24:23 +02:00
parent 75fbb93180
commit fa1d43345a
6 changed files with 91 additions and 8 deletions

View File

@ -1262,18 +1262,42 @@ MDIView* Document::getActiveView(void) const
Gui::MDIView* Document::getViewOfViewProvider(Gui::ViewProvider* vp) const
{
std::list<MDIView*> mdis = getMDIViews();
std::list<MDIView*> mdis = getMDIViewsOfType(View3DInventor::getClassTypeId());
for (std::list<MDIView*>::const_iterator it = mdis.begin(); it != mdis.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(View3DInventor::getClassTypeId())) {
View3DInventor* view = static_cast<View3DInventor*>(*it);
if (view->getViewer()->hasViewProvider(vp))
return *it;
}
View3DInventor* view = static_cast<View3DInventor*>(*it);
if (view->getViewer()->hasViewProvider(vp))
return *it;
}
return 0;
}
Gui::MDIView* Document::getFirstViewOfViewProvider(Gui::ViewProvider* vp) const
{
// first try the active view
Gui::MDIView* view = getActiveView();
if (view && view->isDerivedFrom(View3DInventor::getClassTypeId())) {
View3DInventor* view3d = static_cast<View3DInventor*>(view);
if (view3d->getViewer()->hasViewProvider(vp))
return view;
}
return getViewOfViewProvider(vp);
}
std::list<MDIView*> Document::getViewsOfViewProvider(Gui::ViewProvider* vp) const
{
std::list<MDIView*> views;
std::list<MDIView*> mdis = getMDIViewsOfType(View3DInventor::getClassTypeId());
for (std::list<MDIView*>::const_iterator it = mdis.begin(); it != mdis.end(); ++it) {
View3DInventor* view = static_cast<View3DInventor*>(*it);
if (view->getViewer()->hasViewProvider(vp))
views.push_back(*it);
}
return views;
}
//--------------------------------------------------------------------------
// UNDO REDO transaction handling
//--------------------------------------------------------------------------

View File

@ -148,8 +148,10 @@ public:
//@{
/// Getter for the active view
Gui::MDIView* getActiveView(void) const;
Gui::MDIView* getFirstViewOfViewProvider(Gui::ViewProvider*) const;
Gui::MDIView* getViewOfViewProvider(Gui::ViewProvider*) const;
/// Creat a new view
std::list<MDIView*> getViewsOfViewProvider(Gui::ViewProvider*) const;
/// Create a new view
void createView(const Base::Type& typeId);
/** send messages to the active view
* Send a specific massage to the active view and is able to recive a

View File

@ -166,6 +166,9 @@ void ConstraintView::contextMenuEvent (QContextMenuEvent* event)
);
rename->setEnabled(item != 0);
QAction* center = menu.addAction(tr("Center sketch"), this, SLOT(centerSelectedItems()));
center->setEnabled(item != 0);
QAction* remove = menu.addAction(tr("Delete"), this, SLOT(deleteSelectedItems()),
QKeySequence(QKeySequence::Delete));
remove->setEnabled(!items.isEmpty());
@ -198,6 +201,11 @@ void ConstraintView::renameCurrentItem()
editItem(item);
}
void ConstraintView::centerSelectedItems()
{
Q_EMIT emitCenterSelectedItems();
}
void ConstraintView::deleteSelectedItems()
{
App::Document* doc = App::GetApplication().getActiveDocument();
@ -245,6 +253,10 @@ TaskSketcherConstrains::TaskSketcherConstrains(ViewProviderSketch *sketchView)
ui->listWidgetConstraints, SIGNAL(itemChanged(QListWidgetItem *)),
this , SLOT (on_listWidgetConstraints_itemChanged(QListWidgetItem *))
);
QObject::connect(
ui->listWidgetConstraints, SIGNAL(emitCenterSelectedItems()),
this , SLOT (on_listWidgetConstraints_emitCenterSelectedItems())
);
QObject::connect(
ui->listWidgetConstraints, SIGNAL(onUpdateDrivingStatus(QListWidgetItem *, bool)),
this , SLOT (on_listWidgetConstraints_updateDrivingStatus(QListWidgetItem *, bool))
@ -312,6 +324,11 @@ void TaskSketcherConstrains::on_comboBoxFilter_currentIndexChanged(int)
slotConstraintsChanged();
}
void TaskSketcherConstrains::on_listWidgetConstraints_emitCenterSelectedItems()
{
sketchView->centerSelection();
}
void TaskSketcherConstrains::on_listWidgetConstraints_itemSelectionChanged(void)
{
std::string doc_name = sketchView->getSketchObject()->getDocument()->getName();

View File

@ -51,10 +51,12 @@ protected:
Q_SIGNALS:
void onUpdateDrivingStatus(QListWidgetItem *item, bool status);
void emitCenterSelectedItems();
protected Q_SLOTS:
void modifyCurrentItem();
void renameCurrentItem();
void centerSelectedItems();
void deleteSelectedItems();
void doSelectConstraints();
void updateDrivingStatus();
@ -76,10 +78,11 @@ private:
public Q_SLOTS:
void on_comboBoxFilter_currentIndexChanged(int);
void on_listWidgetConstraints_itemSelectionChanged(void);
void on_listWidgetConstraints_itemSelectionChanged(void);
void on_listWidgetConstraints_itemActivated(QListWidgetItem *item);
void on_listWidgetConstraints_itemChanged(QListWidgetItem * item);
void on_listWidgetConstraints_updateDrivingStatus(QListWidgetItem *item, bool status);
void on_listWidgetConstraints_emitCenterSelectedItems(void);
protected:
void changeEvent(QEvent *e);

View File

@ -1821,6 +1821,40 @@ SbVec3s ViewProviderSketch::getDisplayedSize(const SoImage *iconPtr) const
return iconSize;
}
void ViewProviderSketch::centerSelection()
{
Gui::Document* doc = Gui::Application::Instance->getDocument(getObject()->getDocument());
Gui::View3DInventor* view = qobject_cast<Gui::View3DInventor*>(doc->getFirstViewOfViewProvider(this));
if (!view || !edit)
return;
SoGroup* group = new SoGroup();
group->ref();
for (int i=0; i < edit->constrGroup->getNumChildren(); i++) {
if (edit->SelConstraintSet.find(i) != edit->SelConstraintSet.end()) {
SoSeparator *sep = dynamic_cast<SoSeparator *>(edit->constrGroup->getChild(i));
group->addChild(sep);
}
}
Gui::View3DInventorViewer* viewer = view->getViewer();
SoGetBoundingBoxAction action(viewer->getSoRenderManager()->getViewportRegion());
action.apply(group);
group->unref();
SbBox3f box = action.getBoundingBox();
if (!box.isEmpty()) {
// get cirumscribing sphere
SoCamera* camera = viewer->getSoRenderManager()->getCamera();
SbVec3f direction;
camera->orientation.getValue().multVec(SbVec3f(0, 0, 1), direction);
SbVec3f box_cnt = box.getCenter();
SbVec3f cam_pos = box_cnt + camera->focalDistance.getValue() * direction;
camera->position.setValue(cam_pos);
}
}
void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s &endPos,
const Gui::View3DInventorViewer *viewer)
{

View File

@ -165,6 +165,9 @@ public:
const Gui::View3DInventorViewer *viewer,
const SbVec2s &cursorPos);
/*! Look at the center of the bounding of all selected items */
void centerSelection();
/// box selection method
void doBoxSelection(const SbVec2s &startPos, const SbVec2s &endPos,
const Gui::View3DInventorViewer *viewer);