Skip to content

Commit

Permalink
[Meas]fix crash on active view not 3d view
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Oct 27, 2023
1 parent f111e44 commit b7791d0
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/Mod/Measure/Gui/ViewProviderMeasureBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void ViewProviderMeasureBase::redrawAnnotation()
// Base::Console().Message("VPMB::redrawAnnotation()\n");
}

//! connect to the subject to receive visibility updates
//! connect to the subject to receive visibility updates
void ViewProviderMeasureBase::connectToSubject(App::DocumentObject* subject)
{
if (!subject) {
Expand All @@ -228,8 +228,8 @@ void ViewProviderMeasureBase::connectToSubject(App::DocumentObject* subject)
//NOLINTEND
subject->signalChanged.connect(bndVisibility);
}

//! connect to the subject to receive visibility updates

//! connect to the subject to receive visibility updates
void ViewProviderMeasureBase::connectToSubject(std::vector<App::DocumentObject*> subject)
{
if (subject.empty()) {
Expand All @@ -238,8 +238,8 @@ void ViewProviderMeasureBase::connectToSubject(std::vector<App::DocumentObject*>

//NOLINTBEGIN
auto bndVisibility = boost::bind(&ViewProviderMeasureBase::onSubjectVisibilityChanged, this, bp::_1, bp::_2);
//NOLINTEND

//NOLINTEND

// TODO: should we connect to all the subject objects when there is >1?
auto proxy = subject.front();
proxy->signalChanged.connect(bndVisibility);
Expand All @@ -264,24 +264,33 @@ Measure::MeasureBase* ViewProviderMeasureBase::getMeasureObject()
//! an example of an elementDirection would be the vector from the start of a line to the end.
Base::Vector3d ViewProviderMeasureBase::getTextDirection(Base::Vector3d elementDirection, double tolerance)
{
// TODO: this can fail if the active view is not a 3d view (spreadsheet, techdraw page) and something causes a measure to try to update
// we need to search throught the mdi views for a 3d view and take the direction from it (or decide that if the active view is not 3d,

Check warning on line 268 in src/Mod/Measure/Gui/ViewProviderMeasureBase.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

throught ==> thought, through, throughout
// assume we are looking from the front).
Base::Vector3d viewDirection;
Base::Vector3d upDirection;
auto view = dynamic_cast<Gui::View3DInventor*>(Gui::Application::Instance->activeDocument()->getActiveView());
// if (!view) {
// // Measure doesn't work with this kind of active view. Might be dependency graph, might be TechDraw, or ????
// // i don't know if this can even happen.
// throw Base::RuntimeError("Measure doesn't work with this kind of active view.");
// }
Gui::View3DInventorViewer* viewer = view->getViewer();
Base::Vector3d viewDirection = toVector3d(viewer->getViewDirection()).Normalize();
if (view) {
Gui::View3DInventorViewer* viewer = view->getViewer();
viewDirection = toVector3d(viewer->getViewDirection()).Normalize();
upDirection = toVector3d(viewer->getUpDirection()).Normalize();
// Measure doesn't work with this kind of active view. Might be dependency graph, might be TechDraw, or ????
//throw Base::RuntimeError("Measure doesn't work with this kind of active view.");
} else {
viewDirection = Base::Vector3d(0.0, 1.0, 0.0);
upDirection = Base::Vector3d(0.0, 0.0, 1.0);
}

Base::Vector3d textDirection = elementDirection.Cross(viewDirection);
if (textDirection.Length() < tolerance) {
// either elementDirection and viewDirection are parallel or one of them is null.
viewDirection = toVector3d(viewer->getUpDirection()).Normalize();
textDirection = elementDirection.Cross(viewDirection);
textDirection = elementDirection.Cross(upDirection);
}

return textDirection.Normalize();
}


//! true if the subject of this measurement is visible. For Measures that have multiple object subject,
//! all of the subjects must be visible.
bool ViewProviderMeasureBase::isSubjectVisible()
Expand Down

0 comments on commit b7791d0

Please sign in to comment.