Refined Drawing::FeatureViewAnnotation

+ Now goes inside an existing page automatically
+ Supports Rotation value
This commit is contained in:
Yorik van Havre 2012-05-03 16:04:48 -03:00
parent 95922640a0
commit d4b5a079d9
2 changed files with 22 additions and 8 deletions

View File

@ -66,21 +66,20 @@ App::DocumentObjectExecReturn *FeatureViewAnnotation::execute(void)
hg << hex << setfill('0') << setw(2) << (int)(255.0*c.g);
hb << hex << setfill('0') << setw(2) << (int)(255.0*c.b);
result << "<text"
<< " id=\"" << Label.getValue() << "\"" << endl
<< " x=\"" << X.getValue() << "\"" << endl
<< " y=\"" << Y.getValue() << "\"" << endl
result << "<g transform=\"translate(" << X.getValue() << "," << Y.getValue() << ")"
<< " rotate(" << Rotation.getValue() << ")\">" << endl
<< "<text id=\"" << Label.getValue() << "\"" << endl
<< " font-family=\"" << Font.getValue() << "\"" << endl
<< " font-size=\"" << Scale.getValue() << "\"" << endl
<< " fill=\"#" << hr.str() << hg.str() << hb.str() << "\">" << endl;
int index=0;
for (std::vector<std::string>::const_iterator it = Text.getValues().begin(); it != Text.getValues().end(); ++it) {
result << "<tspan x=\"" << X.getValue() << "\" dy=\"1em\">" << it->c_str() << "</tspan>" << endl;
result << "<tspan x=\"0\" dy=\"1em\">" << it->c_str() << "</tspan>" << endl;
index++;
}
result << "</text>" << endl;
result << "</text>" << endl << "</g>" << endl;
// Apply the resulting fragment
ViewResult.setValue(result.str().c_str());

View File

@ -374,8 +374,23 @@ CmdDrawingAnnotation::CmdDrawingAnnotation()
void CmdDrawingAnnotation::activated(int iMsg)
{
doCommand(Doc,"AnnotationView = App.activeDocument().addObject(\"Drawing::FeatureViewAnnotation\",\"ViewAnnotation\")");
doCommand(Doc,"AnnotationView.Scale = 7.0");
std::vector<App::DocumentObject*> pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
if (pages.empty()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page to insert"),
QObject::tr("Create a page to insert."));
return;
}
std::string PageName = pages.front()->getNameInDocument();
std::string FeatName = getUniqueObjectName("Annotation");
openCommand("Create Annotation");
doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewAnnotation','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 7.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
updateActive();
commitCommand();
}
bool CmdDrawingAnnotation::isActive(void)