Ejemplo n.º 1
1
void MainFrame::OnAddElementsClick(wxCommandEvent& event)
{
    Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());

    if(workspace) {
        if(workspace->GetWorkspaceMode() != Workspace::MODE_INSERT) {
            auto elementList = workspace->GetElementList();
            wxString statusBarText = "";
            bool newElement = false;

            switch(event.GetId()) {
                case ID_ADDMENU_BUS: {
                    Bus* newBus = new Bus(wxPoint2DDouble(0, 0),
                                          wxString::Format(_("Bus %d"), workspace->GetElementNumber(ID_BUS)));
                    workspace->IncrementElementNumber(ID_BUS);
                    elementList.push_back(newBus);
                    statusBarText = _("Insert Bus: Click to insert, ESC to cancel.");
                    newElement = true;
                } break;
                case ID_ADDMENU_LINE: {
                    Line* newLine = new Line(wxString::Format(_("Line %d"), workspace->GetElementNumber(ID_LINE)));
                    elementList.push_back(newLine);
                    workspace->IncrementElementNumber(ID_LINE);
                    statusBarText = _("Insert Line: Click on two buses, ESC to cancel.");
                    newElement = true;
                } break;
                case ID_ADDMENU_TRANSFORMER: {
                    Transformer* newTransformer = new Transformer(
                        wxString::Format(_("Transformer %d"), workspace->GetElementNumber(ID_TRANSFORMER)));
                    workspace->IncrementElementNumber(ID_TRANSFORMER);
                    elementList.push_back(newTransformer);
                    statusBarText = _("Insert Transformer: Click on two buses, ESC to cancel.");
                    newElement = true;
                } break;
                case ID_ADDMENU_GENERATOR: {
                    SyncGenerator* newGenerator = new SyncGenerator(
                        wxString::Format(_("Generator %d"), workspace->GetElementNumber(ID_SYNCGENERATOR)));
                    workspace->IncrementElementNumber(ID_SYNCGENERATOR);
                    elementList.push_back(newGenerator);
                    statusBarText = _("Insert Generator: Click on a buses, ESC to cancel.");
                    newElement = true;
                } break;
                case ID_ADDMENU_LOAD: {
                    Load* newLoad = new Load(wxString::Format(_("Load %d"), workspace->GetElementNumber(ID_LOAD)));
                    workspace->IncrementElementNumber(ID_LOAD);
                    elementList.push_back(newLoad);
                    statusBarText = _("Insert Load: Click on a buses, ESC to cancel.");
                    newElement = true;
                } break;
                case ID_ADDMENU_CAPACITOR: {
                    Capacitor* newCapacitor =
                        new Capacitor(wxString::Format(_("Capacitor %d"), workspace->GetElementNumber(ID_CAPACITOR)));
                    workspace->IncrementElementNumber(ID_CAPACITOR);
                    elementList.push_back(newCapacitor);
                    statusBarText = _("Insert Capacitor: Click on a buses, ESC to cancel.");
                    newElement = true;
                } break;
                case ID_ADDMENU_INDUCTOR: {
                    Inductor* newInductor =
                        new Inductor(wxString::Format(_("Inductor %d"), workspace->GetElementNumber(ID_INDUCTOR)));
                    workspace->IncrementElementNumber(ID_INDUCTOR);
                    elementList.push_back(newInductor);
                    statusBarText = _("Insert Inductor: Click on a buses, ESC to cancel.");
                    newElement = true;
                } break;
                case ID_ADDMENU_INDMOTOR: {
                    IndMotor* newIndMotor = new IndMotor(
                        wxString::Format(_("Induction motor %d"), workspace->GetElementNumber(ID_INDMOTOR)));
                    workspace->IncrementElementNumber(ID_INDMOTOR);
                    elementList.push_back(newIndMotor);
                    statusBarText = _("Insert Induction Motor: Click on a buses, ESC to cancel.");
                    newElement = true;
                } break;
                case ID_ADDMENU_SYNCCOMP: {
                    SyncMotor* newSyncCondenser = new SyncMotor(
                        wxString::Format(_("Synchronous condenser %d"), workspace->GetElementNumber(ID_SYNCMOTOR)));
                    workspace->IncrementElementNumber(ID_SYNCMOTOR);
                    elementList.push_back(newSyncCondenser);
                    statusBarText = _("Insert Synchronous Condenser: Click on a buses, ESC to cancel.");
                    newElement = true;
                } break;
            }
            if(newElement) {
                workspace->SetElementList(elementList);
                workspace->SetWorkspaceMode(Workspace::MODE_INSERT);
                workspace->SetStatusBarText(statusBarText);
                workspace->Redraw();
            }
        }
    }
}
Ejemplo n.º 2
0
void MainFrame::OnMoveClick(wxRibbonButtonBarEvent& event)
{
    Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
    if(workspace) {
        auto elementList = workspace->GetAllElements();
        // Calculate the average position of selected elements.
        wxPoint2DDouble averagePos(0, 0);
        int numSelElements = 0;
        for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
            Element* element = *it;
            if(element->IsSelected()) {
                averagePos += element->GetPosition();
                numSelElements++;
            }
        }
        averagePos = wxPoint2DDouble(averagePos.m_x / double(numSelElements), averagePos.m_y / double(numSelElements));
        // Set the move position to the average of selected elements.
        for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
            Element* element = *it;
            if(element->IsSelected()) { element->StartMove(averagePos); }
        }
        workspace->SetWorkspaceMode(Workspace::MODE_MOVE_ELEMENT);
    }
}