summaryrefslogtreecommitdiffstats
path: root/src/circuitview.cpp
blob: 5e90448ac6426c9ef82e378ecae8ce51ae2cf37a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

#include "circuitdocument.h"
#include "circuitview.h"
#include "config.h"
#include "ktechlab.h"
#include "simulator.h"
#include "viewiface.h"

#include <tdelocale.h>
#include <tqwhatsthis.h>

CircuitView::CircuitView( CircuitDocument * circuitDocument, ViewContainer *viewContainer, uint viewAreaId, const char *name )
	: ICNView( circuitDocument, viewContainer, viewAreaId, name ),
	p_circuitDocument(circuitDocument)
{
	TDEActionCollection * ac = actionCollection();
	
	new TDEAction( "Dump linear equations", TQt::CTRL|TQt::Key_D, circuitDocument, TQT_SLOT(displayEquations()), ac, "dump_les" );
	
	//BEGIN Item Control Actions
	TDERadioAction * ra;
	ra = new TDERadioAction( i18n("0 Degrees"), "", 0, circuitDocument, TQT_SLOT(setOrientation0()), ac, "edit_orientation_0" );
	ra->setExclusiveGroup("orientation");
	ra->setChecked(true);
	ra = new TDERadioAction( i18n("90 Degrees"), "", 0, circuitDocument, TQT_SLOT(setOrientation90()), ac, "edit_orientation_90" );
	ra->setExclusiveGroup("orientation");
	ra = new TDERadioAction( i18n("180 Degrees"), "", 0, circuitDocument, TQT_SLOT(setOrientation180()), ac, "edit_orientation_180" );
	ra->setExclusiveGroup("orientation");
	ra =new TDERadioAction( i18n("270 Degrees"), "", 0, circuitDocument, TQT_SLOT(setOrientation270()), ac, "edit_orientation_270" );
	ra->setExclusiveGroup("orientation");
	
	new TDEAction( i18n("Create Subcircuit"), "", 0, circuitDocument, TQT_SLOT(createSubcircuit()), ac, "circuit_create_subcircuit" );
	new TDEAction( i18n("Rotate Clockwise"), "object-rotate-right", "]", circuitDocument, TQT_SLOT(rotateClockwise()), ac, "edit_rotate_cw" );
	new TDEAction( i18n("Rotate Counter-Clockwise"), "object-rotate-left", "[", circuitDocument, TQT_SLOT(rotateCounterClockwise()), ac, "edit_rotate_ccw" );
	new TDEAction( i18n("Flip"), "", 0, circuitDocument, TQT_SLOT(itemFlip()), ac, "edit_flip" );
	//END Item Control Actions
	
	setXMLFile( "ktechlabcircuitui.rc", true );
	
	
	TQWhatsThis::add( this, i18n(
			"Construct a circuit by dragging components from the Component selector from the left. Create the connections by dragging a wire from the component connectors.<br><br>"
					
			"The simulation is running by default, but can be paused and resumed from the Tools menu.<br><br>"
					
			"To delete a wire, select it with a select box, and hit delete.<br><br>"
					
			"To edit the attributes of a component, select it (making sure that no components of another type are also selected), and edit in the toolbar. More advanced properties can be edited using the item editor on the right.<br><br>"
					
			"Subcircuits can be created by connecting the components with an External Connection, selecting the desired components and clicking on \"Create Subcircuit\" in the right-click menu.")
				   );
	
	m_pViewIface = new CircuitViewIface(this);
	
	m_statusBar->insertItem( "", ViewStatusBar::SimulationState );
	connect( Simulator::self(), TQT_SIGNAL(simulatingStateChanged(bool )), this, TQT_SLOT(slotUpdateRunningStatus(bool )) );
	slotUpdateRunningStatus( Simulator::self()->isSimulating() );
}


CircuitView::~CircuitView()
{
	delete m_pViewIface;
	m_pViewIface = 0l;
}


void CircuitView::slotUpdateRunningStatus( bool isRunning )
{
	m_statusBar->changeItem( isRunning ? i18n("Simulation Running") : i18n("Simulation Paused"), ViewStatusBar::SimulationState );
}


void CircuitView::dragEnterEvent( TQDragEnterEvent * e )
{
	ICNView::dragEnterEvent(e);
	if ( e->isAccepted() )
		return;
	
	e->accept( e->provides("ktechlab/component") || e->provides("ktechlab/subcircuit") );
}

#include "circuitview.moc"