[TD]fix Balloon placement issues
- contributed by @lidiriel
This commit is contained in:
@@ -57,13 +57,17 @@
|
||||
#include "LineGroup.h"
|
||||
|
||||
|
||||
//#include <Mod/TechDraw/App/DrawViewBalloonPy.h> // generated from DrawViewDimensionPy.xml
|
||||
//#include <Mod/TechDraw/App/DrawViewBalloonPy.h> // generated from DrawViewBalloonPy.xml
|
||||
|
||||
using namespace TechDraw;
|
||||
|
||||
//===========================================================================
|
||||
// DrawViewDimension
|
||||
// DrawViewBalloon
|
||||
//===========================================================================
|
||||
//
|
||||
// X,Y is the center of the balloon bubble
|
||||
// OriginX, OriginY is the tip of the arrow
|
||||
// these are in ???? coordinates
|
||||
|
||||
PROPERTY_SOURCE(TechDraw::DrawViewBalloon, TechDraw::DrawView)
|
||||
|
||||
@@ -83,7 +87,8 @@ const char* DrawViewBalloon::balloonTypeEnums[]= {"Circular",
|
||||
DrawViewBalloon::DrawViewBalloon(void)
|
||||
{
|
||||
ADD_PROPERTY_TYPE(Text , (""),"",App::Prop_None,"The text to be displayed");
|
||||
ADD_PROPERTY_TYPE(sourceView,(0),"",(App::PropertyType)(App::Prop_None),"Source view for balloon");
|
||||
// ADD_PROPERTY_TYPE(SourceView,(0),"",(App::PropertyType)(App::Prop_None),"Source view for balloon");
|
||||
ADD_PROPERTY_TYPE(SourceView,(0),"",(App::PropertyType)(App::Prop_None),"Source view for balloon");
|
||||
ADD_PROPERTY_TYPE(OriginX,(0),"",(App::PropertyType)(App::Prop_None),"Balloon origin x");
|
||||
ADD_PROPERTY_TYPE(OriginY,(0),"",(App::PropertyType)(App::Prop_None),"Balloon origin y");
|
||||
ADD_PROPERTY_TYPE(OriginIsSet, (false), "",(App::PropertyType)(App::Prop_None),"Balloon origin is set");
|
||||
@@ -103,8 +108,8 @@ DrawViewBalloon::DrawViewBalloon(void)
|
||||
OriginIsSet.setStatus(App::Property::Hidden,false);
|
||||
OriginIsSet.setStatus(App::Property::ReadOnly,true);
|
||||
|
||||
sourceView.setScope(App::LinkScope::Global);
|
||||
// sourceView.setStatus(App::Property::Hidden,true);
|
||||
SourceView.setScope(App::LinkScope::Global);
|
||||
// SourceView.setStatus(App::Property::Hidden,true);
|
||||
Rotation.setStatus(App::Property::Hidden,true);
|
||||
// ScaleType.setStatus(App::Property::Hidden,true);
|
||||
// Scale.setStatus(App::Property::Hidden,true);
|
||||
@@ -123,9 +128,16 @@ void DrawViewBalloon::onChanged(const App::Property* prop)
|
||||
DrawView::onChanged(prop);
|
||||
}
|
||||
|
||||
void DrawViewBalloon::onDocumentRestored()
|
||||
void DrawViewBalloon::handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName)
|
||||
{
|
||||
|
||||
// was sourceView in the past, now is SourceView
|
||||
Base::Type type = Base::Type::fromName(TypeName);
|
||||
if (SourceView.getClassTypeId() == type && strcmp(PropName, "sourceView") == 0) {
|
||||
SourceView.Restore(reader);
|
||||
}
|
||||
else {
|
||||
DrawView::handleChangedPropertyName(reader, TypeName, PropName);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawViewBalloon::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
|
||||
@@ -187,9 +199,33 @@ short DrawViewBalloon::mustExecute() const
|
||||
return DrawView::mustExecute();
|
||||
}
|
||||
|
||||
void DrawViewBalloon::handleXYLock(void) {
|
||||
if (isLocked()) {
|
||||
if (!OriginX.testStatus(App::Property::ReadOnly)) {
|
||||
OriginX.setStatus(App::Property::ReadOnly, true);
|
||||
OriginX.purgeTouched();
|
||||
}
|
||||
if (!OriginY.testStatus(App::Property::ReadOnly)) {
|
||||
OriginY.setStatus(App::Property::ReadOnly, true);
|
||||
OriginY.purgeTouched();
|
||||
}
|
||||
} else {
|
||||
if (OriginX.testStatus(App::Property::ReadOnly)) {
|
||||
OriginX.setStatus(App::Property::ReadOnly, false);
|
||||
OriginX.purgeTouched();
|
||||
}
|
||||
if (OriginY.testStatus(App::Property::ReadOnly)) {
|
||||
OriginY.setStatus(App::Property::ReadOnly, false);
|
||||
OriginY.purgeTouched();
|
||||
}
|
||||
}
|
||||
DrawView::handleXYLock();
|
||||
}
|
||||
|
||||
|
||||
DrawViewPart* DrawViewBalloon::getViewPart() const
|
||||
{
|
||||
App::DocumentObject* obj = sourceView.getValue();
|
||||
App::DocumentObject* obj = SourceView.getValue();
|
||||
DrawViewPart* result = dynamic_cast<DrawViewPart*>(obj);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ public:
|
||||
DrawViewBalloon();
|
||||
virtual ~DrawViewBalloon();
|
||||
|
||||
App::PropertyLink sourceView;
|
||||
/* App::PropertyLink sourceView;*/
|
||||
App::PropertyLink SourceView;
|
||||
App::PropertyString Text;
|
||||
App::PropertyEnumeration EndType;
|
||||
App::PropertyEnumeration Symbol;
|
||||
@@ -77,10 +78,13 @@ public:
|
||||
static const char* balloonTypeEnums[];
|
||||
static const char* endTypeEnums[];
|
||||
|
||||
void handleXYLock(void) override;
|
||||
|
||||
protected:
|
||||
void onChanged(const App::Property* prop);
|
||||
virtual void onDocumentRestored();
|
||||
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop);
|
||||
/* virtual void onDocumentRestored();*/
|
||||
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop);
|
||||
virtual void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -247,6 +247,7 @@ void QGIView::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
|
||||
//TODO: this should be done in itemChange - item position has changed
|
||||
//TODO: and should check for dragging
|
||||
// Base::Console().Message("QGIV::mouseReleaseEvent() - %s\n",getViewName());
|
||||
// if(scene() && this == scene()->mouseGrabberItem()) {
|
||||
if(!m_locked) {
|
||||
if (!isInnerView()) {
|
||||
double tempX = x(),
|
||||
|
||||
@@ -130,6 +130,8 @@ void QGIBalloonLabel::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
|
||||
|
||||
void QGIBalloonLabel::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
// Base::Console().Message("QGIVB::mouseRelease - pos: %s\n",
|
||||
// DrawUtil::formatVector(pos()).c_str());
|
||||
m_ctrl = false;
|
||||
if(scene() && this == scene()->mouseGrabberItem()) {
|
||||
Q_EMIT dragFinished();
|
||||
@@ -308,16 +310,18 @@ QGIViewBalloon::QGIViewBalloon() :
|
||||
|
||||
}
|
||||
|
||||
//from QGVP::mouseReleaseEvent - pos = eventPos
|
||||
void QGIViewBalloon::placeBalloon(QPointF pos)
|
||||
{
|
||||
|
||||
// Base::Console().Message("QGIVB::placeBalloon(%s)\n",
|
||||
// DrawUtil::formatVector(pos).c_str());
|
||||
auto balloon( dynamic_cast<TechDraw::DrawViewBalloon*>(getViewObject()) );
|
||||
if( balloon == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
DrawView* balloonParent = nullptr;
|
||||
App::DocumentObject* docObj = balloon->sourceView.getValue();
|
||||
App::DocumentObject* docObj = balloon->SourceView.getValue();
|
||||
if (docObj == nullptr) {
|
||||
return;
|
||||
} else {
|
||||
@@ -334,8 +338,10 @@ void QGIViewBalloon::placeBalloon(QPointF pos)
|
||||
return;
|
||||
}
|
||||
|
||||
balloon->OriginX.setValue(mapFromScene(pos).x());
|
||||
balloon->OriginY.setValue(mapFromScene(pos).y());
|
||||
balloon->OriginX.setValue(Rez::appX(mapFromScene(pos).x()));
|
||||
balloon->OriginY.setValue(Rez::appX(mapFromScene(pos).y()));
|
||||
balloon->X.setValue(Rez::appX(mapFromScene(pos).x() + 200));
|
||||
balloon->Y.setValue(- Rez::appX(mapFromScene(pos).y() - 200));
|
||||
|
||||
int idx = featPage->getNextBalloonIndex();
|
||||
QString labelText = QString::number(idx);
|
||||
@@ -405,6 +411,11 @@ void QGIViewBalloon::updateView(bool update)
|
||||
balloonLabel->setDimString(labelText, Rez::guiX(balloon->TextWrapLen.getValue()));
|
||||
balloonLabel->setColor(getNormalColor());
|
||||
}
|
||||
if ( balloon->X.isTouched() || balloon->Y.isTouched()){
|
||||
float x = Rez::guiX(balloon->X.getValue());
|
||||
float y = Rez::guiX(balloon->Y.getValue());
|
||||
balloonLabel->setPosFromCenter(x,-y);
|
||||
}
|
||||
|
||||
updateBalloon();
|
||||
draw();
|
||||
@@ -429,6 +440,7 @@ void QGIViewBalloon::updateBalloon(bool obtuse)
|
||||
|
||||
QString labelText = QString::fromUtf8(balloon->Text.getStrValue().data());
|
||||
balloonLabel->verticalSep = false;
|
||||
balloonLabel->seps.clear();
|
||||
|
||||
if (strcmp(balloon->Symbol.getValueAsString(), "Rectangle") == 0) {
|
||||
while (labelText.contains(QString::fromUtf8("|"))) {
|
||||
@@ -441,6 +453,7 @@ void QGIViewBalloon::updateBalloon(bool obtuse)
|
||||
}
|
||||
|
||||
balloonLabel->setDimString(labelText, Rez::guiX(balloon->TextWrapLen.getValue()));
|
||||
balloonLabel->setPosFromCenter(balloonLabel->X(),balloonLabel->Y());
|
||||
}
|
||||
|
||||
void QGIViewBalloon::balloonLabelDragged(bool ctrl)
|
||||
@@ -450,17 +463,18 @@ void QGIViewBalloon::balloonLabelDragged(bool ctrl)
|
||||
|
||||
void QGIViewBalloon::balloonLabelDragFinished()
|
||||
{
|
||||
auto dim( dynamic_cast<TechDraw::DrawViewBalloon *>(getViewObject()) );
|
||||
auto dvb( dynamic_cast<TechDraw::DrawViewBalloon *>(getViewObject()) );
|
||||
|
||||
if( dim == nullptr ) {
|
||||
if( dvb == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
//this needs to be scaled?
|
||||
double x = Rez::appX(balloonLabel->X()),
|
||||
y = Rez::appX(balloonLabel->Y());
|
||||
Gui::Command::openCommand("Drag Balloon");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", dim->getNameInDocument(), x);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", dim->getNameInDocument(), -y);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", dvb->getNameInDocument(), x);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", dvb->getNameInDocument(), -y);
|
||||
Gui::Command::commitCommand();
|
||||
}
|
||||
|
||||
@@ -509,8 +523,6 @@ void QGIViewBalloon::draw_modifier(bool modifier)
|
||||
Base::Vector3d lblCenter = Base::Vector3d(mappedRect.center().x(), mappedRect.center().y(), 0.0);
|
||||
|
||||
if (balloon->isLocked()) {
|
||||
lblCenter.x = (oldLabelCenter->x());
|
||||
lblCenter.y = (oldLabelCenter->y());
|
||||
balloonLabel->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
} else
|
||||
balloonLabel->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
@@ -519,8 +531,8 @@ void QGIViewBalloon::draw_modifier(bool modifier)
|
||||
Base::Vector3d kinkPoint;
|
||||
double kinkLength = Rez::guiX(5.0);
|
||||
|
||||
float orginX = balloon->OriginX.getValue();
|
||||
float orginY = balloon->OriginY.getValue();
|
||||
float orginX = Rez::guiX(balloon->OriginX.getValue());
|
||||
float orginY = Rez::guiX(balloon->OriginY.getValue());
|
||||
|
||||
const char *balloonType = balloon->Symbol.getValueAsString();
|
||||
|
||||
@@ -609,12 +621,12 @@ void QGIViewBalloon::draw_modifier(bool modifier)
|
||||
dLinePath.lineTo(kinkPoint.x, kinkPoint.y);
|
||||
|
||||
if (modifier) {
|
||||
balloon->OriginX.setValue(orginX + lblCenter.x - oldLabelCenter->x());
|
||||
balloon->OriginY.setValue(orginY + lblCenter.y - oldLabelCenter->y());
|
||||
balloon->OriginX.setValue(Rez::appX(orginX + lblCenter.x - oldLabelCenter->x()));
|
||||
balloon->OriginY.setValue(Rez::appX(orginY + lblCenter.y - oldLabelCenter->y()));
|
||||
}
|
||||
|
||||
orginX = balloon->OriginX.getValue();
|
||||
orginY = balloon->OriginY.getValue();
|
||||
orginX = Rez::guiX(balloon->OriginX.getValue());
|
||||
orginY = Rez::guiX(balloon->OriginY.getValue());
|
||||
|
||||
dLinePath.lineTo(orginX, orginY);
|
||||
|
||||
|
||||
@@ -639,7 +639,7 @@ QGIView * QGVPage::findParent(QGIView *view) const
|
||||
balloon = dynamic_cast<TechDraw::DrawViewBalloon *>(myFeat);
|
||||
|
||||
if(balloon) {
|
||||
App::DocumentObject* obj = balloon->sourceView.getValue();
|
||||
App::DocumentObject* obj = balloon->SourceView.getValue();
|
||||
|
||||
if(obj) {
|
||||
// Attach the dimension to the first object's group
|
||||
@@ -1163,7 +1163,7 @@ void QGVPage::mouseReleaseEvent(QMouseEvent *event)
|
||||
throw Base::TypeError("CmdTechDrawNewBalloon - balloon not found\n");
|
||||
}
|
||||
|
||||
balloon->sourceView.setValue(getDrawPage()->balloonParent);
|
||||
balloon->SourceView.setValue(getDrawPage()->balloonParent);
|
||||
balloon->origin = mapToScene(event->pos());
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
Reference in New Issue
Block a user