Add unti support to Sketcher

This commit is contained in:
jriegel
2013-12-15 22:47:25 +01:00
parent 2b10890a04
commit d5d9ea9c30
17 changed files with 296 additions and 230 deletions

View File

@@ -81,10 +81,6 @@ void EditDatumDialog::exec(bool atCursor)
return;
}
double datum = Constr->Value;
if (Constr->Type == Sketcher::Angle)
datum = Base::toDegrees<double>(datum);
Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView();
Gui::View3DInventorViewer *viewer = static_cast<Gui::View3DInventor *>(mdi)->getViewer();
@@ -92,30 +88,48 @@ void EditDatumDialog::exec(bool atCursor)
Ui::InsertDatum ui_ins_datum;
ui_ins_datum.setupUi(&dlg);
double datum = Constr->Value;
Base::Quantity init_val;
if (Constr->Type == Sketcher::Angle){
datum = Base::toDegrees<double>(datum);
init_val.setUnit(Base::Unit::Angle);
ui_ins_datum.labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherAngle"));
}else{
init_val.setUnit(Base::Unit::Length);
ui_ins_datum.labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherLength"));
}
//ui_ins_datum.lineEdit->setParamGrpPath("User parameter:History/Sketcher/SetDatum");
double init_val;
if (Constr->Type == Sketcher::Angle ||
((Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY) &&
Constr->FirstPos == Sketcher::none || Constr->Second != Sketcher::Constraint::GeoUndef))
// hide negative sign
init_val = std::abs(datum);
else // show negative sign
init_val = datum;
init_val.setValue(std::abs(datum));
ui_ins_datum.lineEdit->setText(QLocale::system().toString(init_val,'g',6));
ui_ins_datum.lineEdit->selectAll();
else // show negative sign
init_val.setValue(datum);
ui_ins_datum.labelEdit->setValue(init_val);
ui_ins_datum.labelEdit->selectNumber();
if (atCursor)
dlg.setGeometry(QCursor::pos().x() - dlg.geometry().width() / 2, QCursor::pos().y(), dlg.geometry().width(), dlg.geometry().height());
if (dlg.exec()) {
bool ok;
double newDatum = QLocale::system().toDouble(ui_ins_datum.lineEdit->text(), &ok);
if (ok) {
Base::Quantity newQuant = ui_ins_datum.labelEdit->getQuantity();
if (newQuant.isQuantity()) {
// save the value for the history
ui_ins_datum.labelEdit->pushToHistory();
double newDatum;
if (Constr->Type == Sketcher::Angle)
newDatum = Base::toRadians<double>(newDatum);
newDatum = Base::toRadians<double>(newQuant.getValue());
else
newDatum = newQuant.getValue();
if (Constr->Type == Sketcher::Angle ||
((Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY) &&

View File

@@ -27,7 +27,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
<widget class="Gui::InputField" name="labelEdit"/>
</item>
</layout>
</item>

View File

@@ -77,7 +77,7 @@ SoDatumLabel::SoDatumLabel()
SO_NODE_ADD_FIELD(norm, (SbVec3f(.0f,.0f,1.f)));
SO_NODE_ADD_FIELD(name, ("Helvetica"));
SO_NODE_ADD_FIELD(size, (12.f));
SO_NODE_ADD_FIELD(size, (10.f));
SO_NODE_ADD_FIELD(lineWidth, (2.f));
SO_NODE_ADD_FIELD(datumtype, (SoDatumLabel::DISTANCE));
@@ -92,6 +92,8 @@ SoDatumLabel::SoDatumLabel()
SO_NODE_ADD_FIELD(param1, (0.f));
SO_NODE_ADD_FIELD(param2, (0.f));
useAntialiasing = true;
this->imgWidth = 0;
this->imgHeight = 0;
this->glimagevalid = false;
@@ -127,7 +129,8 @@ void SoDatumLabel::drawImage()
image.fill(0x00000000);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
if(useAntialiasing)
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(front);
painter.setFont(font);

View File

@@ -71,6 +71,7 @@ public:
SoSFVec3f norm;
SoSFImage image;
SoSFFloat lineWidth;
bool useAntialiasing;
protected:
virtual ~SoDatumLabel() {};

View File

@@ -256,31 +256,36 @@ void TaskSketcherConstrains::slotConstraintsChanged(void)
break;
case Sketcher::Distance:
if(Filter<3 || (*it)->Name != ""){
name = QString::fromLatin1("%1 (%2)").arg(name).arg((*it)->Value);
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity((*it)->Value,Base::Unit::Length).getUserString());
//name = QString::fromLatin1("%1 (%2)").arg(name).arg((*it)->Value);
ui->listWidgetConstraints->addItem(new ConstraintItem(dist,name,i-1,(*it)->Type));
}
break;
case Sketcher::DistanceX:
if(Filter<3 || (*it)->Name != ""){
name = QString::fromLatin1("%1 (%2)").arg(name).arg(std::abs((*it)->Value));
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity((*it)->Value,Base::Unit::Length).getUserString());
//name = QString::fromLatin1("%1 (%2)").arg(name).arg(std::abs((*it)->Value));
ui->listWidgetConstraints->addItem(new ConstraintItem(hdist,name,i-1,(*it)->Type));
}
break;
case Sketcher::DistanceY:
if(Filter<3 || (*it)->Name != ""){
name = QString::fromLatin1("%1 (%2)").arg(name).arg(std::abs((*it)->Value));
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity((*it)->Value,Base::Unit::Length).getUserString());
//name = QString::fromLatin1("%1 (%2)").arg(name).arg(std::abs((*it)->Value));
ui->listWidgetConstraints->addItem(new ConstraintItem(vdist,name,i-1,(*it)->Type));
}
break;
case Sketcher::Radius:
if(Filter<3 || (*it)->Name != ""){
name = QString::fromLatin1("%1 (%2)").arg(name).arg((*it)->Value);
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity((*it)->Value,Base::Unit::Length).getUserString());
//name = QString::fromLatin1("%1 (%2)").arg(name).arg((*it)->Value);
ui->listWidgetConstraints->addItem(new ConstraintItem(radi,name,i-1,(*it)->Type));
}
break;
case Sketcher::Angle:
if(Filter<3 || (*it)->Name != ""){
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::toDegrees<double>(std::abs((*it)->Value)));
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::Quantity(Base::toDegrees<double>(std::abs((*it)->Value)),Base::Unit::Angle).getUserString());
//name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::toDegrees<double>(std::abs((*it)->Value)));
ui->listWidgetConstraints->addItem(new ConstraintItem(angl,name,i-1,(*it)->Type));
}
break;

View File

@@ -2424,9 +2424,11 @@ Restart:
if ((Constr->Type == DistanceX || Constr->Type == DistanceY) &&
Constr->FirstPos != Sketcher::none && Constr->Second == Constraint::GeoUndef)
// display negative sign for absolute coordinates
asciiText->string = SbString().sprintf("%.2f",Constr->Value);
asciiText->string = SbString(Base::Quantity(Constr->Value,Base::Unit::Length).getUserString().toUtf8().constData());
//asciiText->string = SbString().sprintf("%.2f",Constr->Value);
else // hide negative sign
asciiText->string = SbString().sprintf("%.2f",std::abs(Constr->Value));
asciiText->string = SbString(Base::Quantity(std::abs(Constr->Value),Base::Unit::Length).getUserString().toUtf8().constData());
//asciiText->string = SbString().sprintf("%.2f",std::abs(Constr->Value));
if (Constr->Type == Distance)
asciiText->datumtype = SoDatumLabel::DISTANCE;
@@ -2642,7 +2644,8 @@ Restart:
break;
SoDatumLabel *asciiText = dynamic_cast<SoDatumLabel *>(sep->getChild(0));
asciiText->string = SbString().sprintf("%.2f",Base::toDegrees<double>(std::abs(Constr->Value)));
asciiText->string = SbString(Base::Quantity(Base::toDegrees<double>(std::abs(Constr->Value)),Base::Unit::Angle).getUserString().toUtf8().constData());
//asciiText->string = SbString().sprintf("%.2f",Base::toDegrees<double>(std::abs(Constr->Value)));
asciiText->datumtype = SoDatumLabel::ANGLE;
asciiText->param1 = Constr->LabelDistance;
asciiText->param2 = startangle;
@@ -2763,6 +2766,8 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
text->norm.setValue(norm);
text->string = "";
text->textColor = ConstrDimColor;
text->size.setValue(17);
text->useAntialiasing = false;
SoAnnotation *anno = new SoAnnotation();
anno->renderCaching = SoSeparator::OFF;
anno->addChild(text);
@@ -3166,7 +3171,7 @@ void ViewProviderSketch::createEditInventorNodes(void)
Coordsep->renderCaching = SoSeparator::OFF;
SoFont *font = new SoFont();
font->size = 15.0;
font->size = 10.0;
Coordsep->addChild(font);
edit->textPos = new SoTranslation();