Skip to content

Commit

Permalink
[TD]fix Projection Group front view position
Browse files Browse the repository at this point in the history
- also fix checkbox correspondence with view position
  • Loading branch information
WandererFan committed Feb 29, 2024
1 parent 677cade commit cbc39e9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
5 changes: 1 addition & 4 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ bool DrawProjGroup::canDelete(const char* viewProjType) const

App::DocumentObject* DrawProjGroup::addProjection(const char* viewProjType)
{
// Base::Console().Message("DPG::addProjection(%s)\n", viewProjType ? viewProjType : "null");
DrawProjGroupItem* view(nullptr);
std::pair<Base::Vector3d, Base::Vector3d> vecs;

Expand Down Expand Up @@ -499,10 +500,6 @@ App::DocumentObject* DrawProjGroup::addProjection(const char* viewProjType)
true);//Front should stay locked.
view->LockPosition.purgeTouched();
}
// addView(view); //from DrawViewCollection
// if (view != getAnchor()) { //anchor is done elsewhere
// view->recomputeFeature();
// }
}
}
return view;
Expand Down
16 changes: 13 additions & 3 deletions src/Mod/TechDraw/Gui/QGSPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;
using DU = DrawUtil;

QGSPage::QGSPage(ViewProviderPage* vpPage, QWidget* parent)
: QGraphicsScene(parent), pageTemplate(nullptr), m_vpPage(nullptr)
Expand Down Expand Up @@ -254,13 +255,21 @@ int QGSPage::addQView(QGIView* view)
TechDraw::DrawView *viewObj = view->getViewObject();
// Preserve the desired position, as addToGroup() adjusts the child view's position
QPointF viewPos(Rez::guiX(viewObj->X.getValue()), -Rez::guiX(viewObj->Y.getValue()));

// Find if it belongs to a parent
QGIView *parent = findParent(view);
if (parent) {
auto parentDocObj = parent->getViewObject();
auto parentDPG = dynamic_cast<TechDraw::DrawProjGroup*>(parentDocObj);
if (parentDPG) {
// move the DPGI to the center of the DPG. the DPGI must be placed in the
// correct position on the page before adding it to the DPG or it will be
// placed at scene(0,0).
QPointF posRef(0., 0.);
QPointF mapPos = view->mapToItem(parent, posRef);
view->moveBy(-mapPos.x(), -mapPos.y());
}
parent->addToGroup(view);
}

view->setPos(viewPos);

auto viewProvider = dynamic_cast<ViewProviderDrawingView *>(QGIView::getViewProvider(view->getViewObject()));
Expand Down Expand Up @@ -389,7 +398,7 @@ bool QGSPage::attachView(App::DocumentObject* obj)

QGIView* QGSPage::addViewPart(TechDraw::DrawViewPart* partFeat)
{
// Base::Console().Message("QGSP::addViewPart(%s)\n", part->getNameInDocument());
// Base::Console().Message("QGSP::addViewPart(%s)\n", partFeat->Label.getValue());
auto viewPart(new QGIViewPart);

viewPart->setViewPartFeature(partFeat);
Expand All @@ -410,6 +419,7 @@ QGIView* QGSPage::addViewSection(DrawViewSection* sectionFeat)

QGIView* QGSPage::addProjectionGroup(TechDraw::DrawProjGroup* projGroupFeat)
{
// Base::Console().Message("QGSP::addprojectionGroup(%s)\n", projGroupFeat->Label.getValue());
auto qview(new QGIProjGroup);

qview->setViewFeature(projGroupFeat);
Expand Down
34 changes: 19 additions & 15 deletions src/Mod/TechDraw/Gui/TaskProjGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void TaskProjGroup::viewToggled(bool toggle)
// Obtain name of checkbox
QString viewName = sender()->objectName();
int index = viewName.mid(7).toInt();
const char *viewNameCStr = viewChkIndexToCStr(index).c_str();
const char *viewNameCStr = viewChkIndexToCStr(index);
if ( toggle && !multiView->hasProjection( viewNameCStr ) ) {
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.addProjection('%s')",
Expand All @@ -198,6 +198,7 @@ void TaskProjGroup::viewToggled(bool toggle)
double scale = multiView->getScale();
setFractionalScale(scale);
}
multiView->recomputeFeature();
}
wc.restoreCursor();
}
Expand Down Expand Up @@ -247,6 +248,8 @@ void TaskProjGroup::projectionTypeChanged(QString qText)
ui->chkView7->setToolTip(getToolTipForBox(7));
ui->chkView8->setToolTip(getToolTipForBox(8));
ui->chkView9->setToolTip(getToolTipForBox(9));

multiView->recomputeFeature();
}

void TaskProjGroup::scaleTypeChanged(int index)
Expand Down Expand Up @@ -428,7 +431,7 @@ void TaskProjGroup::changeEvent(QEvent *event)
}
}

std::string TaskProjGroup::viewChkIndexToCStr(int index)
const char * TaskProjGroup::viewChkIndexToCStr(int index)
{
// Third Angle: FTL T FTRight
// L F Right Rear
Expand All @@ -439,20 +442,20 @@ std::string TaskProjGroup::viewChkIndexToCStr(int index)
// FTRight T FTL
assert (multiView);

std::string boxName;
bool thirdAngle = multiView->usedProjectionType().isValue("Third Angle");
switch(index) {
case 0: {boxName = Base::Tools::toStdString(getToolTipForBox(0)); break;}
case 1: {boxName = Base::Tools::toStdString(getToolTipForBox(1)); break;}
case 2: {boxName = Base::Tools::toStdString(getToolTipForBox(2)); break;}
case 4: {boxName = Base::Tools::toStdString(getToolTipForBox(3)); break;}
case 5: {boxName = Base::Tools::toStdString(getToolTipForBox(4)); break;}
case 6: {boxName = Base::Tools::toStdString(getToolTipForBox(5)); break;}
case 7: {boxName = Base::Tools::toStdString(getToolTipForBox(6)); break;}
case 8: {boxName = Base::Tools::toStdString(getToolTipForBox(7)); break;}
case 9: {boxName = Base::Tools::toStdString(getToolTipForBox(8)); break;}
default: boxName = "";
case 0: return (thirdAngle ? "FrontTopLeft" : "FrontBottomRight");
case 1: return (thirdAngle ? "Top" : "Bottom");
case 2: return (thirdAngle ? "FrontTopRight" : "FrontBottomLeft");
case 3: return (thirdAngle ? "Left" : "Right");
case 4: return (thirdAngle ? "Front" : "Front");
case 5: return (thirdAngle ? "Right" : "Left");
case 6: return (thirdAngle ? "Rear" : "Rear");
case 7: return (thirdAngle ? "FrontBottomLeft" : "FrontTopRight");
case 8: return (thirdAngle ? "Bottom" : "Top");
case 9: return (thirdAngle ? "FrontBottomRight" : "FrontTopLeft");
default: return nullptr;
}
return boxName;
}

QString TaskProjGroup::getToolTipForBox(int boxNumber)
Expand All @@ -477,6 +480,7 @@ void TaskProjGroup::setupViewCheckboxes(bool addConnections)
{
if (!multiView)
return;

// There must be a better way to construct this list...
QCheckBox * viewCheckboxes[] = { ui->chkView0,
ui->chkView1,
Expand All @@ -496,7 +500,7 @@ void TaskProjGroup::setupViewCheckboxes(bool addConnections)
connect(box, &QCheckBox::toggled, this, &TaskProjGroup::viewToggled);
}

const char *viewStr = viewChkIndexToCStr(i).c_str();
const char *viewStr = viewChkIndexToCStr(i);
if (viewStr && multiView->hasProjection(viewStr)) {
box->setCheckState(Qt::Checked);
if (!multiView->canDelete(viewStr)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/TaskProjGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected Q_SLOTS:

bool blockUpdate;
/// Translate a view checkbox index into represented view string, depending on projection type
std::string viewChkIndexToCStr(int index);
const char * viewChkIndexToCStr(int index);
QString getToolTipForBox(int boxNumber);

QPushButton* m_btnOK;
Expand Down

0 comments on commit cbc39e9

Please sign in to comment.