+ fixes #0000870: Center sketch to a constraint that has been double clicked in the constraint list.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user