analog_electricity, some cleaning

parent 7f8b09f8
......@@ -33,7 +33,7 @@ ActivityInfo {
prerequisite: qsTr("Requires some basic understanding of the concept of electricity.")
//: Help manual
manual: qsTr("Drag electrical components from the selector and drop them in the working area. In the working area, you can move the components by dragging them.") + " " + qsTr("To delete a component or wire, select the deletion tool on top of the component selector, and select the component or wire.") + " " + qsTr("You can click on the component and then on the rotate buttons to rotate it or on the info button to get information about it.") + " " + qsTr("You can click on the switch to open and close it. You can change the rheostat value by dragging its slider.") + " " + qsTr("To connect two terminals, click on the first terminal, then on the second terminal. To deselect a terminal, click on any empty area.") + " " + qsTr("In order to repair a broken bulb or LED, click on it after deconnecting it from the circuit. The simulation is updated in real time by any user action.")
credit: qsTr("The electric simulation engine is from edX : ") +
credit: qsTr("The electric simulation engine is from edX: ") +
"<https://github.com/edx/edx-platform/blob/master/common/lib/xmodule/xmodule/js/src/capa/schematic.js>."
section: "sciences experiment"
createdInVersion: 9800
......
......@@ -37,29 +37,29 @@ ActivityBase {
pageComponent: Image {
id: background
anchors.fill: parent
source: Activity.url1 + "texture02.png"
source: Activity.urlDigital + "texture02.png"
fillMode: Image.Tile
signal start
signal stop
onWidthChanged: resizeTimer.restart();
onHeightChanged:resizeTimer.restart();
onHeightChanged: resizeTimer.restart();
Timer {
id: resizeTimer
interval : 200
repeat : false
running : false
triggeredOnStart : false
interval: 200
repeat: false
running: false
triggeredOnStart: false
onTriggered: Activity.updateWiresOnResize();
}
Timer {
id: netlistTimer
interval : 500
repeat : false
running : false
triggeredOnStart : false
interval: 500
repeat: false
running: false
triggeredOnStart: false
onTriggered: Activity.createNetlist();
}
......@@ -107,7 +107,7 @@ ActivityBase {
}
onHoriChanged: {
if (hori == true) {
if (hori === true) {
playArea.x += items.toolsMargin;
playArea.y -= items.toolsMargin;
} else {
......@@ -259,19 +259,15 @@ ActivityBase {
Rectangle {
id: inputComponentsContainer
width: background.hori ?
items.toolsMargin :
background.width
height: background.hori ?
background.height :
items.toolsMargin
width: background.hori ? items.toolsMargin : background.width
height: background.hori ? background.height : items.toolsMargin
color: "#4A3823"
anchors.left: parent.left
Image {
anchors.fill: parent
anchors.rightMargin: background.hori ? 3 * ApplicationInfo.ratio : 0
anchors.bottomMargin: background.hori ? 0 : 3 * ApplicationInfo.ratio
source: Activity.url1 + "texture01.png"
source: Activity.urlDigital + "texture01.png"
fillMode: Image.Tile
ListWidget {
id: availablePieces
......@@ -326,7 +322,7 @@ ActivityBase {
Bar {
id: bar
content: BarEnumContent { value: help | home | level | reload}
content: BarEnumContent { value: help | home | level | reload }
onHelpClicked: displayDialog(dialogHelp);
onPreviousLevelClicked: Activity.previousLevel();
onNextLevelClicked: Activity.nextLevel();
......
......@@ -111,7 +111,7 @@ Item {
height: width
sourceSize.width: width
sourceSize.height: height
source: Activity.url1 + "tools.svg"
source: Activity.urlDigital + "tools.svg"
fillMode: Image.PreserveAspectFit
property bool showToolBar: false
......@@ -153,17 +153,15 @@ Item {
height: width
sourceSize.width: width
sourceSize.height: height
source: Activity.url1 + "deleteOn.svg"
source: Activity.urlDigital + "deleteOn.svg"
fillMode: Image.PreserveAspectFit
MouseArea {
anchors.fill: parent
onClicked: {
toolDelete.state = (toolDelete.state == "selected") ? "notSelected" : "selected";
Activity.toolDelete = !Activity.toolDelete;
// Activity.toolDeleteSticky = false
}
onDoubleClicked: {
// Activity.toolDeleteSticky = true
Activity.toolDelete = true;
toolDelete.state = "selected";
}
......@@ -188,7 +186,7 @@ Item {
Image {
id: info
source: Activity.url1 + "info.svg"
source: Activity.urlDigital + "info.svg"
width: minIconWidth
height: width
sourceSize.width: width
......@@ -197,7 +195,7 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: {
if(!Activity.animationInProgress && parent.state == "canBeSelected") {
if(!Activity.animationInProgress && parent.state === "canBeSelected") {
Activity.displayInfo();
hideToolbar();
}
......@@ -227,7 +225,7 @@ Item {
height: width
sourceSize.width: width
sourceSize.height: height
source: Activity.url1 + "rotate.svg"
source: Activity.urlDigital + "rotate.svg"
fillMode: Image.PreserveAspectFit
state: "CanNotBeSelected"
MouseArea {
......@@ -262,7 +260,7 @@ Item {
height: width
sourceSize.width: width
sourceSize.height: height
source: Activity.url1 + "rotate.svg"
source: Activity.urlDigital + "rotate.svg"
fillMode: Image.PreserveAspectFit
mirror: true
state: "CanNotBeSelected"
......@@ -298,7 +296,7 @@ Item {
height: width
sourceSize.width: width
sourceSize.height: height
source: Activity.url1 + "zoomIn.svg"
source: Activity.urlDigital + "zoomIn.svg"
fillMode: Image.PreserveAspectFit
MouseArea {
......@@ -329,7 +327,7 @@ Item {
height: width
sourceSize.width: width
sourceSize.height: height
source: Activity.url1 + "zoomOut.svg"
source: Activity.urlDigital + "zoomOut.svg"
fillMode: Image.PreserveAspectFit
MouseArea {
......
......@@ -25,13 +25,12 @@
.import "cktsim.js" as Engine
var url = "qrc:/gcompris/src/activities/analog_electricity/resource/";
var url1 = "qrc:/gcompris/src/activities/digital_electricity/resource/";
var urlDigital = "qrc:/gcompris/src/activities/digital_electricity/resource/";
var currentLevel = 1;
var numberOfLevel = 3;
var items;
var toolDelete;
//var toolDeleteSticky;
var animationInProgress;
var selectedIndex;
var selectedTerminal;
......@@ -111,7 +110,6 @@ function initLevel() {
stop();
animationInProgress = false;
toolDelete = false;
// toolDeleteSticky = false;
deselect();
currentZoom = defaultZoom;
viewPort.leftEdge = 0;
......@@ -222,7 +220,6 @@ function createComponent(x, y, componentIndex) {
++uniqueID;
components[index].componentName = components[index].componentName + uniqueID.toString();
components[index].initConnections();
// toolDeleteSticky = false;
deselect();
}
......@@ -295,21 +292,25 @@ function updateWires(index) {
return;
var rotatedAngle = component.initialAngle * Math.PI / 180;
var rotatedAngleSin = Math.sin(rotatedAngle);
var rotatedAngleCos = Math.cos(rotatedAngle);
for(var i = 0 ; i < component.noOfConnectionPoints ; ++i) {
var terminal = component.connectionPoints.itemAt(i);
for(var j = 0 ; j < terminal.wires.length ; ++j) {
var wire = terminal.wires[j];
if(wire.node1 != terminal) {
var otherAngle = wire.node1.parent.initialAngle * Math.PI / 180;
var otherAngleCos = Math.cos(otherAngle);
var otherAngleSin = Math.sin(otherAngle);
var x = wire.node1.xCenterFromComponent;
var y = wire.node1.yCenterFromComponent;
var x1 = wire.node1.xCenter - x + x * Math.cos(otherAngle) - y * Math.sin(otherAngle);
var y1 = wire.node1.yCenter - y + x * Math.sin(otherAngle) + y * Math.cos(otherAngle);
var x1 = wire.node1.xCenter - x + x * otherAngleCos - y * otherAngleSin;
var y1 = wire.node1.yCenter - y + x * otherAngleSin + y * otherAngleCos;
x = terminal.xCenterFromComponent;
y = terminal.yCenterFromComponent;
var x2 = terminal.xCenter - x + x * Math.cos(rotatedAngle) - y * Math.sin(rotatedAngle);
var y2 = terminal.yCenter - y + x * Math.sin(rotatedAngle) + y * Math.cos(rotatedAngle);
var x2 = terminal.xCenter - x + x * rotatedAngleCos - y * rotatedAngleSin;
var y2 = terminal.yCenter - y + x * rotatedAngleSin + y * rotatedAngleCos;
var width = Math.pow((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)),0.5) + 2;
var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1));
......@@ -327,16 +328,18 @@ function updateWires(index) {
for(var j = 0 ; j < terminal.wires.length ; ++j) {
var x = terminal.xCenterFromComponent;
var y = terminal.yCenterFromComponent;
var x1 = terminal.xCenter - x + x * Math.cos(rotatedAngle) - y * Math.sin(rotatedAngle);
var y1 = terminal.yCenter - y + x * Math.sin(rotatedAngle) + y * Math.cos(rotatedAngle);
var x1 = terminal.xCenter - x + x * rotatedAngleCos - y * rotatedAngleSin;
var y1 = terminal.yCenter - y + x * rotatedAngleSin + y * rotatedAngleCos;
var wire = terminal.wires[j];
if(wire.node2 != terminal) {
var otherAngle = wire.node2.parent.initialAngle * Math.PI / 180;
var otherAngleCos = Math.cos(otherAngle);
var otherAngleSin = Math.sin(otherAngle);
x = wire.node2.xCenterFromComponent;
y = wire.node2.yCenterFromComponent;
var x2 = wire.node2.xCenter - x + x * Math.cos(otherAngle) - y * Math.sin(otherAngle);
var y2 = wire.node2.yCenter - y + x * Math.sin(otherAngle) + y * Math.cos(otherAngle);
var x2 = wire.node2.xCenter - x + x * otherAngleCos - y * otherAngleSin;
var y2 = wire.node2.yCenter - y + x * otherAngleSin + y * otherAngleCos;
var width = Math.pow((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)),0.5) + 2;
var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1));
......@@ -358,10 +361,6 @@ function updateWiresOnResize() {
}
function deselect() {
// if(toolDeleteSticky == false) {
// toolDelete = false;
// items.availablePieces.toolDelete.state = "notSelected";
// }
items.availablePieces.rotateLeft.state = "canNotBeSelected";
items.availablePieces.rotateRight.state = "canNotBeSelected";
items.availablePieces.info.state = "canNotBeSelected";
......
......@@ -28,8 +28,10 @@ ElectricalComponent {
terminalSize: 0.2
noOfConnectionPoints: 2
information: qsTr("Battery is used for powering up electrical devices. It can supply voltage in a closed circuit. Which means there should be a path for the current to flow from one terminal of the battery to the other.") + " " + qsTr("If the current in a circuit is too high then the battery can be damaged. Wires can be used to connect components and create the circuit.")
labelText1: "V = " + componentVoltage + "V"
labelText2: "I = " + current + "A"
//: 1st V for Voltage, 2nd V for Volt
labelText1: qsTr("V = %1V").arg(componentVoltage)
//: I for current intensity, A for Ampere
labelText2: qsTr("I = %1A").arg(current)
source: Activity.url + "battery.png"
property double componentVoltage: 0
......
......@@ -27,9 +27,11 @@ ElectricalComponent {
id: bulb // Ammeter on both sides of a resistor
terminalSize: 0.2
noOfConnectionPoints: 2
information: qsTr("Bulb glows when it has enough power. Its intensity is propotional to the supplied voltage. It will be broken if there is a power greater than a certain limit.")
labelText1: "V = " + componentVoltage + "V"
labelText2: "I = " + bulbCurrent + "A"
information: qsTr("Bulb glows when it has enough power. Its intensity is proportional to the supplied voltage. It will be broken if there is a power greater than a certain limit.")
//: 1st V for Voltage, 2nd V for Volt
labelText1: qsTr("V = %1V").arg(componentVoltage)
//: I for current intensity, A for Ampere
labelText2: qsTr("I = %1A").arg(bulbCurrent)
source: Activity.url + "bulb1.png"
property var nodeVoltages: [0, 0]
......
......@@ -119,7 +119,7 @@ Image {
Activity.componentSelected(componentIndex);
}
onClicked: {
if(Activity.toolDelete || Activity.toolDeleteSticky) {
if(Activity.toolDelete) {
if (destructible) {
Activity.removeComponent(componentIndex);
} else {
......
......@@ -30,7 +30,7 @@ ElectricalComponent {
information: qsTr("Red LED converts electrical energy into red light energy. It can glow only if the current flow is in the direction of the arrow. Electrical energy more than a certain limit can break it.")
source: Activity.url + "red_led_off.png"
property var nodeVoltages: [0, 0]
property var nodeVoltages: [0, 0]
property double componentVoltage: 0
property double power: 0
property double powerThreshold: 0.01 //in W
......
......@@ -28,11 +28,13 @@ ElectricalComponent {
terminalSize: 0.2
noOfConnectionPoints: 2
information: qsTr("Resistors are used to reduce the current flow in an electrical circuit.")
labelText1: "V = " + componentVoltage + "V"
labelText2: "I = " + resistorCurrent + "A"
//: 1st V for Voltage, 2nd V for Volt
labelText1: qsTr("V = %1V").arg(componentVoltage)
//: I for current intensity, A for Ampere
labelText2: qsTr("I = %1A").arg(resistorCurrent)
source: Activity.url + "resistor.png"
property var nodeVoltages: [0, 0]
property var nodeVoltages: [0, 0]
property double componentVoltage: 0
property double resistorCurrent: 0
property alias connectionPoints: connectionPoints
......
......@@ -28,8 +28,10 @@ ElectricalComponent {
terminalSize: 0.2
noOfConnectionPoints: 3
information: qsTr("Rheostat is used to vary resistance in an electrical circuit.")
labelText1: "V = " + componentVoltage + "V"
labelText2: "I = " + current + "A"
//: 1st V for Voltage, 2nd V for Volt
labelText1: qsTr("V = %1V").arg(componentVoltage)
//: I for current intensity, A for Ampere
labelText2: qsTr("I = %1A").arg(current)
source: Activity.url + "resistor_track.png"
property var nodeVoltages: [0, 0, 0]
......
......@@ -41,7 +41,7 @@ Image {
width: size * Math.max(parent.paintedHeight, parent.paintedWidth)
height: width
source: Activity.url1 + "tPoint.svg"
source: Activity.urlDigital + "tPoint.svg"
sourceSize.width: width
sourceSize.height: width
antialiasing: true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment