Skip to content

Commit

Permalink
Convert angle 360 to 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 14, 2015
1 parent 17c1031 commit 648e1a4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -1106,6 +1106,9 @@ QImage ShapeAnnotation::getImage()
*/
void ShapeAnnotation::applyRotation(qreal angle)
{
if (angle == 360) {
angle = 0;
}
mTransformation.setRotateAngle(angle);
setTransform(mTransformation.getTransformationMatrix());
mRotation = angle;
Expand Down
6 changes: 6 additions & 0 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -191,6 +191,9 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
mpLibraryTreeItem = pLibraryTreeItem;
mpComponentInfo = pComponentInfo;
mpComponentInfo->setName(name);
if (mpLibraryTreeItem) {
mpComponentInfo->setClassName(mpLibraryTreeItem->getNameStructure());
}
mpGraphicsView = pGraphicsView;
mIsInheritedComponent = false;
mComponentType = Component::Root;
Expand Down Expand Up @@ -725,6 +728,9 @@ QString Component::getTransformationExtent()
void Component::applyRotation(qreal angle)
{
setOriginAndExtents();
if (angle == 360) {
angle = 0;
}
mTransformation.setRotateAngle(angle);
setTransform(mTransformation.getTransformationMatrix());
emit rotationChange();
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -70,6 +70,7 @@ class ComponentInfo : public QObject
public:
ComponentInfo(QString value, QObject *pParent = 0);
void parseComponentInfoString(QString value);
void setClassName(QString className) {mClassName = className;}
QString getClassName() {return mClassName;}
void setName(QString name) {mName = name;}
QString getName() {return mName;}
Expand Down
7 changes: 6 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -479,7 +479,9 @@ void GraphicsView::addComponentToView(QString name, LibraryTreeItem *pLibraryTre
pAddComponentCommand = new AddComponentCommand(name, pLibraryTreeItem, transformationString, position, pComponentInfo, addObject,
openingClass, this);
mpModelWidget->getUndoStack()->push(pAddComponentCommand);
mpModelWidget->updateModelicaText();
if (!openingClass) {
mpModelWidget->updateModelicaText();
}
}

/*!
Expand Down Expand Up @@ -2283,6 +2285,9 @@ void ModelWidget::loadModelWidget()
mpDiagramGraphicsView->removeAllComponents();
mpDiagramGraphicsView->removeAllConnections();
mpDiagramGraphicsView->scene()->clear();
if (mpLibraryTreeItem->getNameStructure().compare("Modelica.Electrical.Analog.Basic.Resistor") == 0) {
qDebug() << mpLibraryTreeItem->getNameStructure();
}
getModelInheritedClasses(mpLibraryTreeItem);
drawModelInheritedClasses();
getModelIconDiagramShapes();
Expand Down
29 changes: 15 additions & 14 deletions OMEdit/OMEditGUI/Util/StringHandler.cpp
Expand Up @@ -1227,20 +1227,21 @@ QString StringHandler::getPlacementAnnotation(QString componentAnnotation)
}

/*!
Reduces Angle to useful values. Finds the angle between 0° and 360°.\n
This functin is useful for performing shapes and components flipping.\n\n
<B>Find the angle between 0° and 360° that corresponds to 1275°</B>\n\n
1275 ÷ 360 = 3.541 the only part we care about is the "3", which tells us that 360° fits into 1275° three times,\n
1275° – 3×360° = 1275° – 1080° = 195°\n\n
<B>Find an angle between 0° and 360° that corresponds to –3742°</B>\n\n
This works somewhat similarly to the previous examples. First we will find how often 360° fits inside 3742°,\n
3742 ÷ 360 = 10.394\n
But since this angle was negative, so we actually need one extra round to carry us into the positive angle values,
so we will use 11 instead of 10,\n
–3742 + 11 × 360 = –3742 + 3960 = 218.
\param angle - the angle to be normalized.
\return the normalized angle.
*/
* \brief StringHandler::getNormalizedAngle
* Reduces Angle to useful values. Finds the angle between 0° and 360°.\n
* This functin is useful for performing shapes and components flipping.\n\n
* <B>Find the angle between 0° and 360° that corresponds to 1275°</B>\n\n
* 1275 ÷ 360 = 3.541 the only part we care about is the "3", which tells us that 360° fits into 1275° three times,\n
* 1275° – 3×360° = 1275° – 1080° = 195°\n\n
* <B>Find an angle between 0° and 360° that corresponds to –3742°</B>\n\n
* This works somewhat similarly to the previous examples. First we will find how often 360° fits inside 3742°,\n
* 3742 ÷ 360 = 10.394\n
* But since this angle was negative, so we actually need one extra round to carry us into the positive angle values,
* so we will use 11 instead of 10,\n
* –3742 + 11 × 360 = –3742 + 3960 = 218.
* \param angle - the angle to be normalized.
* \return the normalized angle.
*/
qreal StringHandler::getNormalizedAngle(qreal angle)
{
qreal multiplier = fabs(angle)/360;
Expand Down

0 comments on commit 648e1a4

Please sign in to comment.