Use Face or 3D direction for View and ProjGroup

- use current 3D window direction as starting
  direction for DrawViewPart and ProjectionGroup
- if a Face is selected, use Face normal as
  starting direction.
This commit is contained in:
wandererfan
2018-08-20 20:01:48 -04:00
committed by wmayer
parent 233ed49b23
commit aa8feb79d0
16 changed files with 544 additions and 893 deletions

View File

@@ -36,6 +36,7 @@
#include <Gui/Document.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <Gui/WaitCursor.h>
#include <Inventor/SbVec3f.h>
@@ -97,10 +98,8 @@ TaskProjGroup::TaskProjGroup(TechDraw::DrawProjGroup* featView, bool mode) :
connect(ui->butLeftRotate, SIGNAL(clicked()), this, SLOT(rotateButtonClicked(void)));
connect(ui->butCCWRotate, SIGNAL(clicked()), this, SLOT(rotateButtonClicked(void)));
//3D button
connect(ui->but3D, SIGNAL(clicked()), this, SLOT(on3DClicked(void)));
//Reset button
connect(ui->butReset, SIGNAL(clicked()), this, SLOT(onResetClicked(void)));
// //Reset button
// connect(ui->butReset, SIGNAL(clicked()), this, SLOT(onResetClicked(void)));
// Slot for Scale Type
connect(ui->cmbScaleType, SIGNAL(currentIndexChanged(int)), this, SLOT(scaleTypeChanged(int)));
@@ -126,13 +125,17 @@ TaskProjGroup::~TaskProjGroup()
void TaskProjGroup::viewToggled(bool toggle)
{
Gui::WaitCursor wc;
bool changed = false;
// Obtain name of checkbox
QString viewName = sender()->objectName();
int index = viewName.mid(7).toInt();
const char *viewNameCStr = viewChkIndexToCStr(index);
if ( toggle && !multiView->hasProjection( viewNameCStr ) ) {
(void) multiView->addProjection( viewNameCStr );
(void) multiView->addProjection( viewNameCStr ); //maybe this should be send a message instead of blocking?
// Gui::Command::doCommand(Gui::Command::Doc, // Gui response is no faster with this. :(
// "App.activeDocument().%s.addProjection('%s')",
// multiView->getNameInDocument(), viewNameCStr);
changed = true;
} else if ( !toggle && multiView->hasProjection( viewNameCStr ) ) {
multiView->removeProjection( viewNameCStr );
@@ -144,7 +147,7 @@ void TaskProjGroup::viewToggled(bool toggle)
setFractionalScale(scale);
}
}
wc.restoreCursor();
}
void TaskProjGroup::rotateButtonClicked(void)
@@ -171,37 +174,14 @@ void TaskProjGroup::rotateButtonClicked(void)
}
}
void TaskProjGroup::on3DClicked(void)
{
Base::Console().Warning("TaskProjGroup - this function is temporarily unavailable\n");
//TODO: how to set the DPG.Cube (or a brand new replacement Cube) to a specific orientation
// {10x(viewDirection + RotationVector)} given only the
// viewDirection + upDirection(!= RotationVector) of the front view?
// need to find the sequence of rotations Left/Right, Up/Down, CW/CCW
// from current orientation to desired orientation.
// std::pair<Base::Vector3d,Base::Vector3d> dir3D = get3DViewDir();
// Base::Vector3d dir = dir3D.first;
// dir = DrawUtil::closestBasis(dir);
// Base::Vector3d up = dir3D.second;
// up = DrawUtil::closestBasis(up);
//void TaskProjGroup::onResetClicked(void)
//{
// TechDraw::DrawProjGroupItem* front = multiView->getProjItem("Front");
// if (front) { //why "if front"???
// multiView->setTable(dir,up);
// if (front) {
// setUiPrimary();
// Gui::Command::updateActive();
// }
}
void TaskProjGroup::onResetClicked(void)
{
TechDraw::DrawProjGroupItem* front = multiView->getProjItem("Front");
if (front) {
multiView->resetCube();
setUiPrimary();
Gui::Command::updateActive();
}
}
//}
void TaskProjGroup::projectionTypeChanged(int index)
{
@@ -463,41 +443,6 @@ void TaskProjGroup::setUiPrimary()
ui->lePrimary->setText(formatVector(frontDir));
}
//should return a configuration? frontdir,upDir mapped in DPG
std::pair<Base::Vector3d,Base::Vector3d> TaskProjGroup::get3DViewDir()
{
std::pair<Base::Vector3d,Base::Vector3d> result;
Base::Vector3d viewDir(0.0,-1.0,0.0); //default to front
Base::Vector3d viewUp(0.0,0.0,1.0); //default to top
std::list<MDIView*> mdis = Gui::Application::Instance->activeDocument()->getMDIViews();
Gui::View3DInventor *view;
Gui::View3DInventorViewer *viewer = nullptr;
for (auto& m: mdis) { //find the 3D viewer
view = dynamic_cast<Gui::View3DInventor*>(m);
if (view) {
viewer = view->getViewer();
break;
}
}
if (!viewer) {
Base::Console().Log("LOG - TaskProjGroup could not find a 3D viewer\n");
return std::make_pair( viewDir, viewUp);
}
SbVec3f dvec = viewer->getViewDirection();
SbVec3f upvec = viewer->getUpDirection();
viewDir = Base::Vector3d(dvec[0], dvec[1], dvec[2]);
viewUp = Base::Vector3d(upvec[0],upvec[1],upvec[2]);
viewDir *= -1.0; //Inventor dir is opposite TD dir, Inventor up is same as TD up
viewDir = DrawUtil::closestBasis(viewDir);
viewUp = DrawUtil::closestBasis(viewUp);
result = std::make_pair(viewDir,viewUp);
return result;
}
QString TaskProjGroup::formatVector(Base::Vector3d v)
{
QString data = QString::fromLatin1("[%1 %2 %3]")