コード例 #1
0
void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event )
{
    ARRAY_OPTIONS* newSettings = NULL;

    const wxWindow* page = m_gridTypeNotebook->GetCurrentPage();

    if( page == m_gridPanel )
    {
        ARRAY_GRID_OPTIONS* newGrid = new ARRAY_GRID_OPTIONS();
        bool ok = true;

        // ints
        ok  = ok && m_entryNx->GetValue().ToLong( &newGrid->m_nx );
        ok  = ok && m_entryNy->GetValue().ToLong( &newGrid->m_ny );

        newGrid->m_delta.x = DoubleValueFromString( g_UserUnit, m_entryDx->GetValue() );
        newGrid->m_delta.y = DoubleValueFromString( g_UserUnit, m_entryDy->GetValue() );

        newGrid->m_offset.x = DoubleValueFromString( g_UserUnit, m_entryOffsetX->GetValue() );
        newGrid->m_offset.y = DoubleValueFromString( g_UserUnit, m_entryOffsetY->GetValue() );

        ok = ok && m_entryStagger->GetValue().ToLong( &newGrid->m_stagger );

        newGrid->m_stagger_rows = m_radioBoxGridStaggerType->GetSelection() == 0;

        newGrid->m_horizontalThenVertical = m_radioBoxGridNumberingAxis->GetSelection() == 0;
        newGrid->m_reverseNumberingAlternate = m_checkBoxGridReverseNumbering->GetValue();

        newGrid->m_2dArrayNumbering = m_radioBoxGridNumberingScheme->GetSelection() != 0;

        // this is only correct if you set the choice up according to the enum size and order
        ok = ok && m_choicePriAxisNumbering->GetSelection() < NUMBERING_TYPE_Max
             && m_choiceSecAxisNumbering->GetSelection() < NUMBERING_TYPE_Max;

        // mind undefined casts to enums (should not be able to happen)
        if( ok )
        {
            newGrid->m_priAxisNumType =
                (ARRAY_NUMBERING_TYPE_T) m_choicePriAxisNumbering->GetSelection();
            newGrid->m_secAxisNumType =
                (ARRAY_NUMBERING_TYPE_T) m_choiceSecAxisNumbering->GetSelection();
        }

        // Work out the offsets for the numbering
        ok = ok && getNumberingOffset(
                m_entryGridPriNumberingOffset->GetValue().ToStdString(),
                newGrid->m_priAxisNumType, newGrid->m_numberingOffsetX );

        if( newGrid->m_2dArrayNumbering )
            ok = ok && getNumberingOffset(
                    m_entryGridSecNumberingOffset->GetValue().ToStdString(),
                    newGrid->m_secAxisNumType, newGrid->m_numberingOffsetY );

        newGrid->m_shouldRenumber = m_checkBoxGridRestartNumbering->GetValue();

        // Only use settings if all values are good
        if( ok )
            newSettings = newGrid;
        else
            delete newGrid;
    }
    else if( page == m_circularPanel )
    {
        ARRAY_CIRCULAR_OPTIONS* newCirc = new ARRAY_CIRCULAR_OPTIONS();
        bool ok = true;

        newCirc->m_centre.x = DoubleValueFromString( g_UserUnit, m_entryCentreX->GetValue() );
        newCirc->m_centre.y = DoubleValueFromString( g_UserUnit, m_entryCentreY->GetValue() );

        newCirc->m_angle = DoubleValueFromString( DEGREES, m_entryCircAngle->GetValue() );
        ok = ok && m_entryCircCount->GetValue().ToLong( &newCirc->m_nPts );

        newCirc->m_rotateItems = m_entryRotateItemsCb->GetValue();

        newCirc->m_shouldRenumber = m_checkBoxCircRestartNumbering->GetValue();

        // This is only correct if you set the choice up according to the enum size and order
        ok = ok && m_choiceCircNumberingType->GetSelection() < NUMBERING_TYPE_Max;

        // Mind undefined casts to enums (should not be able to happen)
        if( ok )
            newCirc->m_numberingType =
                (ARRAY_NUMBERING_TYPE_T) m_choiceCircNumberingType->GetSelection();

        ok = ok && m_entryCircNumberingStart->GetValue().ToLong( &newCirc->m_numberingOffset );

        // Only use settings if all values are good
        if( ok )
            newSettings = newCirc;
        else
            delete newCirc;
    }

    // If we got good settings, send them out and finish
    if( newSettings )
    {
        delete *m_settings;

        // assign pointer and ownership here
        *m_settings = newSettings;

        ReadConfigFromControls();

        EndModal( wxID_OK );
    }
}
コード例 #2
0
void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event )
{
    ARRAY_OPTIONS* newSettings = NULL;

    wxArrayString errorStrs;

    const wxWindow* page = m_gridTypeNotebook->GetCurrentPage();

    if( page == m_gridPanel )
    {
        ARRAY_GRID_OPTIONS* newGrid = new ARRAY_GRID_OPTIONS();
        bool ok = true;

        // ints
        ok = ok && validateLongEntry(*m_entryNx, newGrid->m_nx, _("horizontal count"),
                          errorStrs);
        ok = ok && validateLongEntry(*m_entryNy, newGrid->m_ny, _("vertical count"),
                          errorStrs);


        newGrid->m_delta.x = DoubleValueFromString( g_UserUnit, m_entryDx->GetValue() );
        newGrid->m_delta.y = DoubleValueFromString( g_UserUnit, m_entryDy->GetValue() );

        newGrid->m_offset.x = DoubleValueFromString( g_UserUnit, m_entryOffsetX->GetValue() );
        newGrid->m_offset.y = DoubleValueFromString( g_UserUnit, m_entryOffsetY->GetValue() );

        ok = ok && validateLongEntry(*m_entryStagger, newGrid->m_stagger, _("stagger"),
                          errorStrs);

        newGrid->m_stagger_rows = m_radioBoxGridStaggerType->GetSelection() == 0;

        newGrid->m_horizontalThenVertical = m_radioBoxGridNumberingAxis->GetSelection() == 0;
        newGrid->m_reverseNumberingAlternate = m_checkBoxGridReverseNumbering->GetValue();

        newGrid->m_shouldNumber = m_numberingEnabled;

        if ( m_numberingEnabled )
        {
            newGrid->m_2dArrayNumbering = m_radioBoxGridNumberingScheme->GetSelection() != 0;

            bool numOk = validateNumberingTypeAndOffset(
                    *m_entryGridPriNumberingOffset, *m_choicePriAxisNumbering,
                    newGrid->m_priAxisNumType, newGrid->m_numberingOffsetX,
                    errorStrs );

            if( newGrid->m_2dArrayNumbering )
            {
                numOk = validateNumberingTypeAndOffset(
                        *m_entryGridSecNumberingOffset, *m_choiceSecAxisNumbering,
                        newGrid->m_secAxisNumType, newGrid->m_numberingOffsetY,
                        errorStrs ) && numOk;
            }

            ok = ok && numOk;

            newGrid->m_numberingStartIsSpecified = m_rbGridStartNumberingOpt->GetSelection() == 1;
        }

        // Only use settings if all values are good
        if( ok )
            newSettings = newGrid;
        else
            delete newGrid;
    }
    else if( page == m_circularPanel )
    {
        ARRAY_CIRCULAR_OPTIONS* newCirc = new ARRAY_CIRCULAR_OPTIONS();
        bool ok = true;

        newCirc->m_centre.x = DoubleValueFromString( g_UserUnit, m_entryCentreX->GetValue() );
        newCirc->m_centre.y = DoubleValueFromString( g_UserUnit, m_entryCentreY->GetValue() );

        newCirc->m_angle = DoubleValueFromString( DEGREES, m_entryCircAngle->GetValue() );

        ok = ok && validateLongEntry(*m_entryCircCount, newCirc->m_nPts,
                                     _("point count"), errorStrs);

        newCirc->m_rotateItems = m_entryRotateItemsCb->GetValue();

        newCirc->m_shouldNumber = m_numberingEnabled;

        if ( m_numberingEnabled )
        {
            newCirc->m_numberingStartIsSpecified = m_rbCircStartNumberingOpt->GetSelection() == 1;
            newCirc->m_numberingType = NUMBERING_NUMERIC;

            ok = ok && validateLongEntry(*m_entryCircNumberingStart,
                                         newCirc->m_numberingOffset,
                                         _("numbering start"), errorStrs);
        }

        // Only use settings if all values are good
        if( ok )
            newSettings = newCirc;
        else
            delete newCirc;
    }

    // If we got good settings, send them out and finish
    if( newSettings )
    {
        delete m_settings;

        // assign pointer and ownership here
        m_settings = newSettings;
        ReadConfigFromControls();

        EndModal( wxID_OK );
    }
    else
    {
        wxString errorStr;

        if( errorStrs.IsEmpty() )
            errorStr = _("Bad parameters");
        else
            errorStr = boost::algorithm::join( errorStrs, "\n" );

        wxMessageBox( errorStr );
    }
}