analog_electricity, some cleaning

parent 7f8b09f8
...@@ -33,7 +33,7 @@ ActivityInfo { ...@@ -33,7 +33,7 @@ ActivityInfo {
prerequisite: qsTr("Requires some basic understanding of the concept of electricity.") prerequisite: qsTr("Requires some basic understanding of the concept of electricity.")
//: Help manual //: 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.") 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>." "<https://github.com/edx/edx-platform/blob/master/common/lib/xmodule/xmodule/js/src/capa/schematic.js>."
section: "sciences experiment" section: "sciences experiment"
createdInVersion: 9800 createdInVersion: 9800
......
...@@ -37,29 +37,29 @@ ActivityBase { ...@@ -37,29 +37,29 @@ ActivityBase {
pageComponent: Image { pageComponent: Image {
id: background id: background
anchors.fill: parent anchors.fill: parent
source: Activity.url1 + "texture02.png" source: Activity.urlDigital + "texture02.png"
fillMode: Image.Tile fillMode: Image.Tile
signal start signal start
signal stop signal stop
onWidthChanged: resizeTimer.restart(); onWidthChanged: resizeTimer.restart();
onHeightChanged:resizeTimer.restart(); onHeightChanged: resizeTimer.restart();
Timer { Timer {
id: resizeTimer id: resizeTimer
interval : 200 interval: 200
repeat : false repeat: false
running : false running: false
triggeredOnStart : false triggeredOnStart: false
onTriggered: Activity.updateWiresOnResize(); onTriggered: Activity.updateWiresOnResize();
} }
Timer { Timer {
id: netlistTimer id: netlistTimer
interval : 500 interval: 500
repeat : false repeat: false
running : false running: false
triggeredOnStart : false triggeredOnStart: false
onTriggered: Activity.createNetlist(); onTriggered: Activity.createNetlist();
} }
...@@ -107,7 +107,7 @@ ActivityBase { ...@@ -107,7 +107,7 @@ ActivityBase {
} }
onHoriChanged: { onHoriChanged: {
if (hori == true) { if (hori === true) {
playArea.x += items.toolsMargin; playArea.x += items.toolsMargin;
playArea.y -= items.toolsMargin; playArea.y -= items.toolsMargin;
} else { } else {
...@@ -259,19 +259,15 @@ ActivityBase { ...@@ -259,19 +259,15 @@ ActivityBase {
Rectangle { Rectangle {
id: inputComponentsContainer id: inputComponentsContainer
width: background.hori ? width: background.hori ? items.toolsMargin : background.width
items.toolsMargin : height: background.hori ? background.height : items.toolsMargin
background.width
height: background.hori ?
background.height :
items.toolsMargin
color: "#4A3823" color: "#4A3823"
anchors.left: parent.left anchors.left: parent.left
Image { Image {
anchors.fill: parent anchors.fill: parent
anchors.rightMargin: background.hori ? 3 * ApplicationInfo.ratio : 0 anchors.rightMargin: background.hori ? 3 * ApplicationInfo.ratio : 0
anchors.bottomMargin: background.hori ? 0 : 3 * ApplicationInfo.ratio anchors.bottomMargin: background.hori ? 0 : 3 * ApplicationInfo.ratio
source: Activity.url1 + "texture01.png" source: Activity.urlDigital + "texture01.png"
fillMode: Image.Tile fillMode: Image.Tile
ListWidget { ListWidget {
id: availablePieces id: availablePieces
...@@ -326,7 +322,7 @@ ActivityBase { ...@@ -326,7 +322,7 @@ ActivityBase {
Bar { Bar {
id: bar id: bar
content: BarEnumContent { value: help | home | level | reload} content: BarEnumContent { value: help | home | level | reload }
onHelpClicked: displayDialog(dialogHelp); onHelpClicked: displayDialog(dialogHelp);
onPreviousLevelClicked: Activity.previousLevel(); onPreviousLevelClicked: Activity.previousLevel();
onNextLevelClicked: Activity.nextLevel(); onNextLevelClicked: Activity.nextLevel();
......
...@@ -111,7 +111,7 @@ Item { ...@@ -111,7 +111,7 @@ Item {
height: width height: width
sourceSize.width: width sourceSize.width: width
sourceSize.height: height sourceSize.height: height
source: Activity.url1 + "tools.svg" source: Activity.urlDigital + "tools.svg"
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
property bool showToolBar: false property bool showToolBar: false
...@@ -153,17 +153,15 @@ Item { ...@@ -153,17 +153,15 @@ Item {
height: width height: width
sourceSize.width: width sourceSize.width: width
sourceSize.height: height sourceSize.height: height
source: Activity.url1 + "deleteOn.svg" source: Activity.urlDigital + "deleteOn.svg"
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
toolDelete.state = (toolDelete.state == "selected") ? "notSelected" : "selected"; toolDelete.state = (toolDelete.state == "selected") ? "notSelected" : "selected";
Activity.toolDelete = !Activity.toolDelete; Activity.toolDelete = !Activity.toolDelete;
// Activity.toolDeleteSticky = false
} }
onDoubleClicked: { onDoubleClicked: {
// Activity.toolDeleteSticky = true
Activity.toolDelete = true; Activity.toolDelete = true;
toolDelete.state = "selected"; toolDelete.state = "selected";
} }
...@@ -188,7 +186,7 @@ Item { ...@@ -188,7 +186,7 @@ Item {
Image { Image {
id: info id: info
source: Activity.url1 + "info.svg" source: Activity.urlDigital + "info.svg"
width: minIconWidth width: minIconWidth
height: width height: width
sourceSize.width: width sourceSize.width: width
...@@ -197,7 +195,7 @@ Item { ...@@ -197,7 +195,7 @@ Item {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
if(!Activity.animationInProgress && parent.state == "canBeSelected") { if(!Activity.animationInProgress && parent.state === "canBeSelected") {
Activity.displayInfo(); Activity.displayInfo();
hideToolbar(); hideToolbar();
} }
...@@ -227,7 +225,7 @@ Item { ...@@ -227,7 +225,7 @@ Item {
height: width height: width
sourceSize.width: width sourceSize.width: width
sourceSize.height: height sourceSize.height: height
source: Activity.url1 + "rotate.svg" source: Activity.urlDigital + "rotate.svg"
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
state: "CanNotBeSelected" state: "CanNotBeSelected"
MouseArea { MouseArea {
...@@ -262,7 +260,7 @@ Item { ...@@ -262,7 +260,7 @@ Item {
height: width height: width
sourceSize.width: width sourceSize.width: width
sourceSize.height: height sourceSize.height: height
source: Activity.url1 + "rotate.svg" source: Activity.urlDigital + "rotate.svg"
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
mirror: true mirror: true
state: "CanNotBeSelected" state: "CanNotBeSelected"
...@@ -298,7 +296,7 @@ Item { ...@@ -298,7 +296,7 @@ Item {
height: width height: width
sourceSize.width: width sourceSize.width: width
sourceSize.height: height sourceSize.height: height
source: Activity.url1 + "zoomIn.svg" source: Activity.urlDigital + "zoomIn.svg"
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
MouseArea { MouseArea {
...@@ -329,7 +327,7 @@ Item { ...@@ -329,7 +327,7 @@ Item {
height: width height: width
sourceSize.width: width sourceSize.width: width
sourceSize.height: height sourceSize.height: height
source: Activity.url1 + "zoomOut.svg" source: Activity.urlDigital + "zoomOut.svg"
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
MouseArea { MouseArea {
......
...@@ -25,13 +25,12 @@ ...@@ -25,13 +25,12 @@
.import "cktsim.js" as Engine .import "cktsim.js" as Engine
var url = "qrc:/gcompris/src/activities/analog_electricity/resource/"; 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 currentLevel = 1;
var numberOfLevel = 3; var numberOfLevel = 3;
var items; var items;
var toolDelete; var toolDelete;
//var toolDeleteSticky;
var animationInProgress; var animationInProgress;
var selectedIndex; var selectedIndex;
var selectedTerminal; var selectedTerminal;
...@@ -111,7 +110,6 @@ function initLevel() { ...@@ -111,7 +110,6 @@ function initLevel() {
stop(); stop();
animationInProgress = false; animationInProgress = false;
toolDelete = false; toolDelete = false;
// toolDeleteSticky = false;
deselect(); deselect();
currentZoom = defaultZoom; currentZoom = defaultZoom;
viewPort.leftEdge = 0; viewPort.leftEdge = 0;
...@@ -222,7 +220,6 @@ function createComponent(x, y, componentIndex) { ...@@ -222,7 +220,6 @@ function createComponent(x, y, componentIndex) {
++uniqueID; ++uniqueID;
components[index].componentName = components[index].componentName + uniqueID.toString(); components[index].componentName = components[index].componentName + uniqueID.toString();
components[index].initConnections(); components[index].initConnections();
// toolDeleteSticky = false;
deselect(); deselect();
} }
...@@ -295,21 +292,25 @@ function updateWires(index) { ...@@ -295,21 +292,25 @@ function updateWires(index) {
return; return;
var rotatedAngle = component.initialAngle * Math.PI / 180; 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) { for(var i = 0 ; i < component.noOfConnectionPoints ; ++i) {
var terminal = component.connectionPoints.itemAt(i); var terminal = component.connectionPoints.itemAt(i);
for(var j = 0 ; j < terminal.wires.length ; ++j) { for(var j = 0 ; j < terminal.wires.length ; ++j) {
var wire = terminal.wires[j]; var wire = terminal.wires[j];
if(wire.node1 != terminal) { if(wire.node1 != terminal) {
var otherAngle = wire.node1.parent.initialAngle * Math.PI / 180; 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 x = wire.node1.xCenterFromComponent;
var y = wire.node1.yCenterFromComponent; var y = wire.node1.yCenterFromComponent;
var x1 = wire.node1.xCenter - x + x * Math.cos(otherAngle) - y * Math.sin(otherAngle); var x1 = wire.node1.xCenter - x + x * otherAngleCos - y * otherAngleSin;
var y1 = wire.node1.yCenter - y + x * Math.sin(otherAngle) + y * Math.cos(otherAngle); var y1 = wire.node1.yCenter - y + x * otherAngleSin + y * otherAngleCos;
x = terminal.xCenterFromComponent; x = terminal.xCenterFromComponent;
y = terminal.yCenterFromComponent; y = terminal.yCenterFromComponent;
var x2 = terminal.xCenter - x + x * Math.cos(rotatedAngle) - y * Math.sin(rotatedAngle); var x2 = terminal.xCenter - x + x * rotatedAngleCos - y * rotatedAngleSin;
var y2 = terminal.yCenter - y + x * Math.sin(rotatedAngle) + y * Math.cos(rotatedAngle); 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 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)); var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1));
...@@ -327,16 +328,18 @@ function updateWires(index) { ...@@ -327,16 +328,18 @@ function updateWires(index) {
for(var j = 0 ; j < terminal.wires.length ; ++j) { for(var j = 0 ; j < terminal.wires.length ; ++j) {
var x = terminal.xCenterFromComponent; var x = terminal.xCenterFromComponent;
var y = terminal.yCenterFromComponent; var y = terminal.yCenterFromComponent;
var x1 = terminal.xCenter - x + x * Math.cos(rotatedAngle) - y * Math.sin(rotatedAngle); var x1 = terminal.xCenter - x + x * rotatedAngleCos - y * rotatedAngleSin;
var y1 = terminal.yCenter - y + x * Math.sin(rotatedAngle) + y * Math.cos(rotatedAngle); var y1 = terminal.yCenter - y + x * rotatedAngleSin + y * rotatedAngleCos;
var wire = terminal.wires[j]; var wire = terminal.wires[j];
if(wire.node2 != terminal) { if(wire.node2 != terminal) {
var otherAngle = wire.node2.parent.initialAngle * Math.PI / 180; var otherAngle = wire.node2.parent.initialAngle * Math.PI / 180;
var otherAngleCos = Math.cos(otherAngle);
var otherAngleSin = Math.sin(otherAngle);
x = wire.node2.xCenterFromComponent; x = wire.node2.xCenterFromComponent;
y = wire.node2.yCenterFromComponent; y = wire.node2.yCenterFromComponent;
var x2 = wire.node2.xCenter - x + x * Math.cos(otherAngle) - y * Math.sin(otherAngle); var x2 = wire.node2.xCenter - x + x * otherAngleCos - y * otherAngleSin;
var y2 = wire.node2.yCenter - y + x * Math.sin(otherAngle) + y * Math.cos(otherAngle); 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 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)); var angle = (180/Math.PI)*Math.atan((y2-y1)/(x2-x1));
...@@ -358,10 +361,6 @@ function updateWiresOnResize() { ...@@ -358,10 +361,6 @@ function updateWiresOnResize() {
} }
function deselect() { function deselect() {
// if(toolDeleteSticky == false) {
// toolDelete = false;
// items.availablePieces.toolDelete.state = "notSelected";
// }
items.availablePieces.rotateLeft.state = "canNotBeSelected"; items.availablePieces.rotateLeft.state = "canNotBeSelected";
items.availablePieces.rotateRight.state = "canNotBeSelected"; items.availablePieces.rotateRight.state = "canNotBeSelected";
items.availablePieces.info.state = "canNotBeSelected"; items.availablePieces.info.state = "canNotBeSelected";
......
...@@ -28,8 +28,10 @@ ElectricalComponent { ...@@ -28,8 +28,10 @@ ElectricalComponent {
terminalSize: 0.2 terminalSize: 0.2
noOfConnectionPoints: 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.") 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" //: 1st V for Voltage, 2nd V for Volt
labelText2: "I = " + current + "A" labelText1: qsTr("V = %1V").arg(componentVoltage)
//: I for current intensity, A for Ampere
labelText2: qsTr("I = %1A").arg(current)
source: Activity.url + "battery.png" source: Activity.url + "battery.png"
property double componentVoltage: 0 property double componentVoltage: 0
......
...@@ -27,9 +27,11 @@ ElectricalComponent { ...@@ -27,9 +27,11 @@ ElectricalComponent {
id: bulb // Ammeter on both sides of a resistor id: bulb // Ammeter on both sides of a resistor
terminalSize: 0.2 terminalSize: 0.2
noOfConnectionPoints: 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.") 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.")
labelText1: "V = " + componentVoltage + "V" //: 1st V for Voltage, 2nd V for Volt
labelText2: "I = " + bulbCurrent + "A" labelText1: qsTr("V = %1V").arg(componentVoltage)
//: I for current intensity, A for Ampere
labelText2: qsTr("I = %1A").arg(bulbCurrent)
source: Activity.url + "bulb1.png" source: Activity.url + "bulb1.png"
property var nodeVoltages: [0, 0] property var nodeVoltages: [0, 0]
......
...@@ -119,7 +119,7 @@ Image { ...@@ -119,7 +119,7 @@ Image {
Activity.componentSelected(componentIndex); Activity.componentSelected(componentIndex);
} }
onClicked: { onClicked: {
if(Activity.toolDelete || Activity.toolDeleteSticky) { if(Activity.toolDelete) {
if (destructible) { if (destructible) {
Activity.removeComponent(componentIndex); Activity.removeComponent(componentIndex);
} else { } else {
......
...@@ -30,7 +30,7 @@ ElectricalComponent { ...@@ -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.") 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" source: Activity.url + "red_led_off.png"
property var nodeVoltages: [0, 0] property var nodeVoltages: [0, 0]
property double componentVoltage: 0 property double componentVoltage: 0
property double power: 0 property double power: 0
property double powerThreshold: 0.01 //in W property double powerThreshold: 0.01 //in W
......
...@@ -28,11 +28,13 @@ ElectricalComponent { ...@@ -28,11 +28,13 @@ ElectricalComponent {
terminalSize: 0.2 terminalSize: 0.2
noOfConnectionPoints: 2 noOfConnectionPoints: 2
information: qsTr("Resistors are used to reduce the current flow in an electrical circuit.") information: qsTr("Resistors are used to reduce the current flow in an electrical circuit.")
labelText1: "V = " + componentVoltage + "V" //: 1st V for Voltage, 2nd V for Volt
labelText2: "I = " + resistorCurrent + "A" labelText1: qsTr("V = %1V").arg(componentVoltage)
//: I for current intensity, A for Ampere
labelText2: qsTr("I = %1A").arg(resistorCurrent)
source: Activity.url + "resistor.png" source: Activity.url + "resistor.png"
property var nodeVoltages: [0, 0] property var nodeVoltages: [0, 0]
property double componentVoltage: 0 property double componentVoltage: 0
property double resistorCurrent: 0 property double resistorCurrent: 0
property alias connectionPoints: connectionPoints property alias connectionPoints: connectionPoints
......
...@@ -28,8 +28,10 @@ ElectricalComponent { ...@@ -28,8 +28,10 @@ ElectricalComponent {
terminalSize: 0.2 terminalSize: 0.2
noOfConnectionPoints: 3 noOfConnectionPoints: 3
information: qsTr("Rheostat is used to vary resistance in an electrical circuit.") information: qsTr("Rheostat is used to vary resistance in an electrical circuit.")
labelText1: "V = " + componentVoltage + "V" //: 1st V for Voltage, 2nd V for Volt
labelText2: "I = " + current + "A" 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" source: Activity.url + "resistor_track.png"
property var nodeVoltages: [0, 0, 0] property var nodeVoltages: [0, 0, 0]
......
...@@ -41,7 +41,7 @@ Image { ...@@ -41,7 +41,7 @@ Image {
width: size * Math.max(parent.paintedHeight, parent.paintedWidth) width: size * Math.max(parent.paintedHeight, parent.paintedWidth)
height: width height: width
source: Activity.url1 + "tPoint.svg" source: Activity.urlDigital + "tPoint.svg"
sourceSize.width: width sourceSize.width: width
sourceSize.height: width sourceSize.height: width
antialiasing: true 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