diff --git a/src/graphicsellipseitem.cpp b/src/graphicsellipseitem.cpp index 083ce32..986d459 100644 --- a/src/graphicsellipseitem.cpp +++ b/src/graphicsellipseitem.cpp @@ -80,11 +80,18 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint, double startSpe for(int i = 1; i< steps;++i) { double myMasse = getMasse( sqrt( speedListX->at(i-1)*speedListX->at(i-1) + speedListY->at(i-1)*speedListY->at(i-1) ) ); - qDebug()<< myMasse; + //qDebug()<< myMasse; double powerX = myScene->getPowerAt(currProbePath->at(i-1), charge, 'x'); double powerY = myScene->getPowerAt(currProbePath->at(i-1), charge, 'y'); - double deltaDistXconst = speedListX->at(i-1) * (timePerStep/1000.0); //v0*t - double deltaDistYconst = speedListY->at(i-1) * (timePerStep/1000.0); + + double newspeedX = speedListX->at(i-1) + (powerX/myMasse * (timePerStep/1000.0)); + double newspeedY = speedListY->at(i-1) + (powerY/myMasse * (timePerStep/1000.0)); + + //double deltaDistXconst = speedListX->at(i-1) * (timePerStep/1000.0); //v0*t + //double deltaDistYconst = speedListY->at(i-1) * (timePerStep/1000.0); + + double deltaDistXconst = (speedListX->at(i-1) + newspeedX)/2.0 * (timePerStep/1000.0); //v0*t + double deltaDistYconst = (speedListY->at(i-1) + newspeedY)/2.0 * (timePerStep/1000.0); //mittel zw alt,neu um fehler zu mindern double deltaDistXaccel = 0.5 * (powerX/myMasse * (timePerStep/1000.0) * (timePerStep/1000.0)); // 1/2 * F/m * t*t double deltaDistYaccel = 0.5 * (powerY/myMasse * (timePerStep/1000.0) * (timePerStep/1000.0)); @@ -93,8 +100,8 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint, double startSpe double deltaDistY = (deltaDistYconst + deltaDistYaccel); currProbePath->append(QPointF(currProbePath->at(i-1).x() + deltaDistX/meterPerPx ,currProbePath->at(i-1).y() + deltaDistY/meterPerPx)); - speedListX->append(speedListX->at(i-1) + (powerX/myMasse * (timePerStep/1000.0)) ); - speedListY->append(speedListY->at(i-1) + (powerY/myMasse * (timePerStep/1000.0)) ); + speedListX->append(newspeedX); + speedListY->append(newspeedY); } diff --git a/src/homobfielditem.cpp b/src/homobfielditem.cpp new file mode 100644 index 0000000..433e07e --- /dev/null +++ b/src/homobfielditem.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Dahlberg * + * pdahlberg@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "homobfielditem.h" +#include +#include + +HomoBFieldItem::HomoBFieldItem(QRectF sizeRect): FieldItem() { + setFieldLineDistance(10); + setFlag(ItemIsMovable); + setFlag(ItemIsSelectable); + setFlag(ItemIsFocusable); + setOuterPenWidth (2); +} + + +HomoBFieldItem::~HomoBFieldItem() +{ +} + + +QRectF HomoBFieldItem::boundingRect() const { + return QRectF(sizeRect.x() - outerPenWidth, sizeRect.y() - outerPenWidth, + sizeRect.width() + outerPenWidth, sizeRect.height() + outerPenWidth); +} + +QRectF HomoBFieldItem::getRectF() const +{ + return FieldItem::getRectF(); +} + +void HomoBFieldItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + Qt::GlobalColor linecolor = Qt::blue; + painter->setPen(linecolor); + if (isSelected()) painter->setBrush(Qt::Dense6Pattern); //selection deutlich machen + painter->drawRect(sizeRect); + + for (int i = 1; i <= floor(sizeRect.width()/(qreal)fieldLineDistance); ++i) { + const int top_bottom_space = 10; + const int arrow_height = 8; //pfeilhoehe + const int arrow_width_half = 3; //Halbe pfeilbreite + + if ((i*fieldLineDistance)+arrow_width_half >= sizeRect.width() -2) break; //rechts ueberstehen verhindern + if (sizeRect.height() < top_bottom_space + arrow_height) break;//nur zeichnen, wenn sizeRect hoch genug + + //Feldlinien zeichnen + painter->drawLine( + sizeRect.x() + (i*fieldLineDistance) , + sizeRect.y() +top_bottom_space , + sizeRect.x() + (i*fieldLineDistance) , + sizeRect.y() + sizeRect.height() - top_bottom_space + ); + + + //Pfeile Zeichnen + QPointF arrows[3] = { + QPointF(sizeRect.x()+(i*fieldLineDistance), sizeRect.y()+sizeRect.height()-top_bottom_space), + QPointF(sizeRect.x()+(i*fieldLineDistance)-arrow_width_half,sizeRect.y()+sizeRect.height()-top_bottom_space-arrow_height), + QPointF(sizeRect.x()+(i*fieldLineDistance)+arrow_width_half,sizeRect.y()+sizeRect.height()-top_bottom_space-arrow_height), + }; + painter->setBrush(linecolor); + painter->drawPolygon(arrows,3); + painter->setBrush(Qt::NoBrush); + + //qDebug() << pos(); + } +} + +int HomoBFieldItem::type() const { + return Type; +} + +int HomoBFieldItem::getFieldLineDistance() const { + return fieldLineDistance; +} + + +void HomoBFieldItem::setFieldLineDistance ( int theValue ) { + if(fieldLineDistance == theValue) return; + fieldLineDistance = theValue; +} + + +double HomoBFieldItem::getOuterPenWidth() const { + return outerPenWidth; +} + + +void HomoBFieldItem::setOuterPenWidth ( double theValue ) { + outerPenWidth = theValue; +} diff --git a/src/homobfielditem.h b/src/homobfielditem.h new file mode 100644 index 0000000..b853093 --- /dev/null +++ b/src/homobfielditem.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2008 by Peter Dahlberg * + * pdahlberg@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef HOMOBFIELDITEM_H +#define HOMOBFIELDITEM_H + +#include + +/** + @author Peter Dahlberg +*/ +class HomoBFieldItem : public FieldItem { + Q_OBJECT + public: + enum {Type = UserType + 2}; + enum {MinimumWidth = 20}; + enum {MinimumHeight = 30}; + + HomoBFieldItem(QRectF sizeRect); + + virtual ~HomoBFieldItem(); + + virtual QRectF boundingRect() const; + virtual QRectF getRectF() const; + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); + int type() const; + + int getFieldLineDistance() const; + + double getOuterPenWidth() const; + public slots: + void setOuterPenWidth ( double theValue ); + void setFieldLineDistance ( int theValue ); + + + + private: + //! Abstand der Feldlinien in der Zeichnung + int fieldLineDistance; + double outerPenWidth; + +}; + +#endif diff --git a/src/homoefielditem.cpp b/src/homoefielditem.cpp index a6f525b..4ce07a1 100644 --- a/src/homoefielditem.cpp +++ b/src/homoefielditem.cpp @@ -33,7 +33,7 @@ HomoEFieldItem::HomoEFieldItem(QRectF sizeRect) setFlag(ItemIsMovable); setFlag(ItemIsSelectable); setFlag(ItemIsFocusable); - outerPenWidth = 2; + setOuterPenWidth (2); //rotateslot(66); @@ -122,3 +122,14 @@ void HomoEFieldItem::setFieldPower (double fieldPower ) { this->fieldPower = fieldPower; emit fieldPowerChanged(fieldPower); } + + +double HomoEFieldItem::getOuterPenWidth() const { + return outerPenWidth; +} + + +void HomoEFieldItem::setOuterPenWidth ( double theValue ) { + if (outerPenWidth == theValue) return; + outerPenWidth = theValue; +} diff --git a/src/homoefielditem.h b/src/homoefielditem.h index c9dbd66..f4ef301 100644 --- a/src/homoefielditem.h +++ b/src/homoefielditem.h @@ -55,6 +55,10 @@ class HomoEFieldItem : public FieldItem { public slots: void setFieldPower (double fieldPower ); + + void setOuterPenWidth ( double theValue ); + double getOuterPenWidth() const; + signals: void fieldPowerChanged(double fieldPower); @@ -62,7 +66,7 @@ class HomoEFieldItem : public FieldItem { //! Abstand der Feldlinien in der Zeichnung int fieldLineDistance; - qreal outerPenWidth; + double outerPenWidth; HomoEFieldWidget* dockWidget; diff --git a/src/lsim.cpp b/src/lsim.cpp index 4862e7f..e16b282 100644 --- a/src/lsim.cpp +++ b/src/lsim.cpp @@ -151,7 +151,7 @@ void lsim::createDocks() { ExpDoubleSpinBox *time_step_box = new ExpDoubleSpinBox; time_step_box->setRange(-pow(10,33), pow(10,33)); - time_step_box->setDecimals(20); + time_step_box->setDecimals(30); time_step_box->setKeyboardTracking(false); time_step_box->setValue(simulscene->getTimePerStep()); @@ -161,7 +161,7 @@ void lsim::createDocks() { ExpDoubleSpinBox *meter_per_px_box = new ExpDoubleSpinBox; meter_per_px_box->setRange(-pow(10,33), pow(10,33)); - meter_per_px_box->setDecimals(20); + meter_per_px_box->setDecimals(30); meter_per_px_box->setKeyboardTracking(false); meter_per_px_box->setValue(simulscene->getMeterPerPx()); connect(meter_per_px_box, SIGNAL(valueChanged(double)),simulscene, SLOT(setMeterPerPx(double))); diff --git a/src/simulscene.cpp b/src/simulscene.cpp index 04a5bd1..0164cba 100644 --- a/src/simulscene.cpp +++ b/src/simulscene.cpp @@ -38,7 +38,7 @@ SimulScene::SimulScene ( QObject* parent ) : QGraphicsScene ( parent ) { //variablen initialisieren setTimePerStep(0.00001); - setSteps(200); + setSteps(1000); //setMeterPerPx(1/1000.0); setMeterPerPx(1); currHomoEfieldInsertItem = 0; diff --git a/src/src.pro b/src/src.pro index b056f91..b4f87bf 100644 --- a/src/src.pro +++ b/src/src.pro @@ -7,7 +7,8 @@ SOURCES += lsim.cpp \ simulscene.cpp \ expdoublespinbox.cpp \ homoefieldwidget.cpp \ - probechargewidget.cpp + probechargewidget.cpp \ + homobfielditem.cpp HEADERS += lsim.h \ graphicsview.h \ graphicsellipseitem.h \ @@ -18,7 +19,8 @@ HEADERS += lsim.h \ lsim_interface.h \ homoefieldwidget.h \ constants.h \ - probechargewidget.h + probechargewidget.h \ + homobfielditem.h TEMPLATE = app CONFIG += warn_on \ thread \