/** * Function idf_export_module * retrieves information from all board modules, adds drill holes to * the DRILLED_HOLES or BOARD_OUTLINE section as appropriate, * compiles data for the PLACEMENT section and compiles data for * the library ELECTRICAL section. */ static void idf_export_module( BOARD* aPcb, MODULE* aModule, IDF3_BOARD& aIDFBoard ) { // Reference Designator std::string crefdes = TO_UTF8( aModule->GetReference() ); if( crefdes.empty() || !crefdes.compare( "~" ) ) { std::string cvalue = TO_UTF8( aModule->GetValue() ); // if both the RefDes and Value are empty or set to '~' the board owns the part, // otherwise associated parts of the module must be marked NOREFDES. if( cvalue.empty() || !cvalue.compare( "~" ) ) crefdes = "BOARD"; else crefdes = "NOREFDES"; } // TODO: If module cutouts are supported we must add code here // for( EDA_ITEM* item = aModule->GraphicalItems(); item != NULL; item = item->Next() ) // { // if( ( item->Type() != PCB_MODULE_EDGE_T ) // || (item->GetLayer() != Edge_Cuts ) ) continue; // code to export cutouts // } // Export pads double drill, x, y; double scale = aIDFBoard.GetUserScale(); IDF3::KEY_PLATING kplate; std::string pintype; std::string tstr; double dx, dy; aIDFBoard.GetUserOffset( dx, dy ); for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() ) { drill = (double) pad->GetDrillSize().x * scale; x = pad->GetPosition().x * scale + dx; y = -pad->GetPosition().y * scale + dy; // Export the hole on the edge layer if( drill > 0.0 ) { // plating if( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) kplate = IDF3::NPTH; else kplate = IDF3::PTH; // hole type tstr = TO_UTF8( pad->GetPadName() ); if( tstr.empty() || !tstr.compare( "0" ) || !tstr.compare( "~" ) || ( kplate == IDF3::NPTH ) ||( pad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ) ) pintype = "MTG"; else pintype = "PIN"; // fields: // 1. hole dia. : float // 2. X coord : float // 3. Y coord : float // 4. plating : PTH | NPTH // 5. Assoc. part : BOARD | NOREFDES | PANEL | {"refdes"} // 6. type : PIN | VIA | MTG | TOOL | { "other" } // 7. owner : MCAD | ECAD | UNOWNED if( ( pad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ) && ( pad->GetDrillSize().x != pad->GetDrillSize().y ) ) { // NOTE: IDF does not have direct support for slots; // slots are implemented as a board cutout and we // cannot represent plating or reference designators double dlength = pad->GetDrillSize().y * scale; // NOTE: The orientation of modules and pads have // the opposite sense due to KiCad drawing on a // screen with a LH coordinate system double angle = pad->GetOrientation() / 10.0; // NOTE: Since this code assumes the scenario where // GetDrillSize().y is the length but idf_parser.cpp // assumes a length along the X axis, the orientation // must be shifted +90 deg when GetDrillSize().y is // the major axis. if( dlength < drill ) { std::swap( drill, dlength ); } else { angle += 90.0; } // NOTE: KiCad measures a slot's length from end to end // rather than between the centers of the arcs dlength -= drill; aIDFBoard.AddSlot( drill, dlength, angle, x, y ); } else { IDF_DRILL_DATA *dp = new IDF_DRILL_DATA( drill, x, y, kplate, crefdes, pintype, IDF3::ECAD ); if( !aIDFBoard.AddDrill( dp ) ) { delete dp; std::ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__; ostr << "(): could not add drill"; throw std::runtime_error( ostr.str() ); } } } } // add any valid models to the library item list std::string refdes; IDF3_COMPONENT* comp = NULL; for( S3D_MASTER* modfile = aModule->Models(); modfile != 0; modfile = modfile->Next() ) { if( !modfile->Is3DType( S3D_MASTER::FILE3D_IDF ) || modfile->GetShape3DFullFilename().empty() ) continue; if( refdes.empty() ) { refdes = TO_UTF8( aModule->GetReference() ); // NOREFDES cannot be used or else the software gets confused // when writing out the placement data due to conflicting // placement and layer specifications; to work around this we // create a (hopefully) unique refdes for our exported part. if( refdes.empty() || !refdes.compare( "~" ) ) refdes = aIDFBoard.GetNewRefDes(); } IDF3_COMP_OUTLINE* outline; outline = aIDFBoard.GetComponentOutline( modfile->GetShape3DFullFilename() ); if( !outline ) throw( std::runtime_error( aIDFBoard.GetError() ) ); double rotz = aModule->GetOrientation()/10.0; double locx = modfile->m_MatPosition.x * 25.4; // part offsets are in inches double locy = modfile->m_MatPosition.y * 25.4; double locz = modfile->m_MatPosition.z * 25.4; double lrot = modfile->m_MatRotation.z; bool top = ( aModule->GetLayer() == B_Cu ) ? false : true; if( top ) { locy = -locy; RotatePoint( &locx, &locy, aModule->GetOrientation() ); locy = -locy; } if( !top ) { lrot = -lrot; RotatePoint( &locx, &locy, aModule->GetOrientation() ); locy = -locy; rotz = 180.0 - rotz; if( rotz >= 360.0 ) while( rotz >= 360.0 ) rotz -= 360.0; if( rotz <= -360.0 ) while( rotz <= -360.0 ) rotz += 360.0; } if( comp == NULL ) comp = aIDFBoard.FindComponent( refdes ); if( comp == NULL ) { comp = new IDF3_COMPONENT( &aIDFBoard ); if( comp == NULL ) throw( std::runtime_error( aIDFBoard.GetError() ) ); comp->SetRefDes( refdes ); if( top ) comp->SetPosition( aModule->GetPosition().x * scale + dx, -aModule->GetPosition().y * scale + dy, rotz, IDF3::LYR_TOP ); else comp->SetPosition( aModule->GetPosition().x * scale + dx, -aModule->GetPosition().y * scale + dy, rotz, IDF3::LYR_BOTTOM ); comp->SetPlacement( IDF3::PS_ECAD ); aIDFBoard.AddComponent( comp ); } else { double refX, refY, refA; IDF3::IDF_LAYER side; if( ! comp->GetPosition( refX, refY, refA, side ) ) { // place the item if( top ) comp->SetPosition( aModule->GetPosition().x * scale + dx, -aModule->GetPosition().y * scale + dy, rotz, IDF3::LYR_TOP ); else comp->SetPosition( aModule->GetPosition().x * scale + dx, -aModule->GetPosition().y * scale + dy, rotz, IDF3::LYR_BOTTOM ); comp->SetPlacement( IDF3::PS_ECAD ); } else { // check that the retrieved component matches this one refX = refX - ( aModule->GetPosition().x * scale + dx ); refY = refY - ( -aModule->GetPosition().y * scale + dy ); refA = refA - rotz; refA *= refA; refX *= refX; refY *= refY; refX += refY; // conditions: same side, X,Y coordinates within 10 microns, // angle within 0.01 degree if( ( top && side == IDF3::LYR_BOTTOM ) || ( !top && side == IDF3::LYR_TOP ) || ( refA > 0.0001 ) || ( refX > 0.0001 ) ) { comp->GetPosition( refX, refY, refA, side ); std::ostringstream ostr; ostr << "* " << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; ostr << "* conflicting Reference Designator '" << refdes << "'\n"; ostr << "* X loc: " << (aModule->GetPosition().x * scale + dx); ostr << " vs. " << refX << "\n"; ostr << "* Y loc: " << (-aModule->GetPosition().y * scale + dy); ostr << " vs. " << refY << "\n"; ostr << "* angle: " << rotz; ostr << " vs. " << refA << "\n"; if( top ) ostr << "* TOP vs. "; else ostr << "* BOTTOM vs. "; if( side == IDF3::LYR_TOP ) ostr << "TOP"; else ostr << "BOTTOM"; throw( std::runtime_error( ostr.str() ) ); } } } // create the local data ... IDF3_COMP_OUTLINE_DATA* data = new IDF3_COMP_OUTLINE_DATA( comp, outline ); data->SetOffsets( locx, locy, locz, lrot ); comp->AddOutlineData( data ); } return; }
wid->setMinimum(0); wid->setMaximum(100); wid->setSingleStep(1); wid->setAccelerated(true); CWIDGET_new(wid, _object); END_METHOD #if 0 BEGIN_PROPERTY(CSPINBOX_prefix) if (READ_PROPERTY) GB.ReturnNewZeroString(TO_UTF8(WIDGET->prefix())); else WIDGET->setPrefix(QSTRING_PROP()); END_PROPERTY BEGIN_PROPERTY(CSPINBOX_suffix) if (READ_PROPERTY) GB.ReturnNewZeroString(TO_UTF8(WIDGET->suffix())); else WIDGET->setSuffix(QSTRING_PROP()); END_PROPERTY #endif
bool CStructureParser::characters(const QString& str) { QRegExp rx("\\w"); QString strAux = str.trimmed(); int pos = rx.indexIn(strAux); std::cout << TO_UTF8(strAux) << std::endl; if (pos != -1) { // handling word character within <mrow> ... </mrow> if (tagName == "mrow") { if (strAux.length() > 1) tex += "{\\text{" + strAux + "}}"; else // exactly only one character tex += "{" + strAux + "}"; } // handling word character within <mi> ... </mi> if (tagName == "mi") { if (strAux.contains("\\")) // for, eg., \sin, \cos tex += strAux; else if (strAux.length() > 1) { if (strAux == "sech" || strAux == "csch" || strAux == "arcsec" || strAux == "arccsc" || strAux == "arccot" || strAux == "arcsinh" || strAux == "arccosh" || strAux == "arctanh" || strAux == "arcsech" || strAux == "arccsch" || strAux == "arccoth") tex += "{\\mathrm{" + strAux + " \\: }}"; else { strAux.replace("_", "\\_"); strAux.replace(" ", "\\;"); tex += "{\\mathrm{" + strAux + "}}"; } } else // exactly only one character tex += "{" + strAux + "}"; } // handling word character within <mo> ... </mo> if (tagName == "mo") { if (strAux.contains("\\")) // for, eg.,\cdot, \ge, \le, \ne { if (strAux == "\\log") tex += " \\, " + strAux; else if (strAux == "\\lt") tex += " \\, < \\, "; else tex += " \\, " + strAux + " \\, "; } else if (strAux.contains("xor")) tex += "\\; \\mathrm{" + strAux + "} \\; "; else if (strAux == "e") tex += strAux; else tex += "\\mathrm{" + strAux + "}"; } // handling word character within <mn> ... </mn> if (tagName == "mn") tex += "{" + strAux + "}"; } // handling non-word character else if (strAux == "=" || strAux == "!" || strAux == "|") tex += strAux; else if (strAux == "-" || strAux == "+" || strAux == ">" || strAux.contains("%")) tex += " \\, " + strAux + " \\, "; return TRUE; }
void CQFittingResult::slotSave(void) { C_INT32 Answer = QMessageBox::No; QString fileName; while (Answer == QMessageBox::No) { fileName = CopasiFileDialog::getSaveFileName(this, "Save File Dialog", "untitled.txt", "TEXT Files (*.txt)", "Save to"); if (fileName.isEmpty()) return; if (!fileName.endsWith(".txt") && !fileName.endsWith(".")) fileName += ".txt"; fileName = fileName.remove(QRegExp("\\.$")); Answer = checkSelection(fileName); if (Answer == QMessageBox::Cancel) return; } std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str()); if (file.fail()) return; int i, imax; // The global result and statistics file << "Objective Value\tRoot Mean Square\tStandard Deviation" << std::endl; file << mpProblem->getSolutionValue() << "\t"; file << mpProblem->getRMS() << "\t"; file << mpProblem->getStdDeviation() << std::endl; file << "Function Evaluations\tCPU Time [s]\tEvaluations/second [1/s]" << std::endl; const unsigned C_INT32 & FunctionEvaluations = mpProblem->getFunctionEvaluations(); const C_FLOAT64 & ExecutionTime = mpProblem->getExecutionTime(); file << FunctionEvaluations << "\t"; file << ExecutionTime << "\t"; file << FunctionEvaluations / ExecutionTime << std::endl << std::endl; if (mpParameters->isEnabled()) { // Set up the parameters table file << "Parameters:" << std::endl; file << "Parameter\tLower Bound\tStart Value\tValue\tUpper Bound\tStd. Deviation\tCoeff. of Variation [%]\tGradient" << std::endl; // Loop over the optimization items imax = mpParameters->rowCount(); for (i = 0; i != imax; i++) { file << TO_UTF8(mpParameters->item((int) i, 0)->text()) << "\t"; file << TO_UTF8(mpParameters->item((int) i, 1)->text()) << "\t"; file << TO_UTF8(mpParameters->item((int) i, 2)->text()) << "\t"; file << TO_UTF8(mpParameters->item((int) i, 3)->text()) << "\t"; file << TO_UTF8(mpParameters->item((int) i, 4)->text()) << "\t"; file << TO_UTF8(mpParameters->item((int) i, 5)->text()) << "\t"; file << TO_UTF8(mpParameters->item((int) i, 6)->text()) << "\t"; file << TO_UTF8(mpParameters->item((int) i, 7)->text()) << std::endl; } file << std::endl; } if (mpExperiments->isEnabled()) { // Set up the experiments table file << "Experiments:" << std::endl; file << "Experiment\tObjective Value\tRoot Mean Square\tError Mean\tError Mean Std. Deviation" << std::endl; // Loop over the experiments imax = mpExperiments->rowCount(); for (i = 0; i != imax; i++) { file << TO_UTF8(mpExperiments->item((int) i, 0)->text()) << "\t"; file << TO_UTF8(mpExperiments->item((int) i, 1)->text()) << "\t"; file << TO_UTF8(mpExperiments->item((int) i, 2)->text()) << "\t"; file << TO_UTF8(mpExperiments->item((int) i, 3)->text()) << "\t"; file << TO_UTF8(mpExperiments->item((int) i, 4)->text()) << std::endl; } file << std::endl; } if (mpValues->isEnabled()) { // Set up the fitted values table file << "Fitted Values:" << std::endl; file << "Fitted Value\tObjective Value\tRoot Mean Square\tError Mean\tError Mean Std. Deviation" << std::endl; // Loop over the fitted values objects imax = mpValues->rowCount(); for (i = 0; i != imax; i++) { file << TO_UTF8(mpValues->item((int) i, 0)->text()) << "\t"; file << TO_UTF8(mpValues->item((int) i, 1)->text()) << "\t"; file << TO_UTF8(mpValues->item((int) i, 2)->text()) << "\t"; file << TO_UTF8(mpValues->item((int) i, 3)->text()) << "\t"; file << TO_UTF8(mpValues->item((int) i, 4)->text()) << std::endl; } file << std::endl; } // Save the parameter correlations file << mpProblem->getCorrelations() << std::endl; // Save the Fisher information file << mpProblem->getFisherInformation() << std::endl; // Save the Fisher information Eigenvalues file << mpProblem->getFisherInformationEigenvalues() << std::endl; // Save the Fisher information Eigenvectors file << mpProblem->getFisherInformationEigenvectors() << std::endl; // Save the scaled Fisher information file << mpProblem->getScaledFisherInformation() << std::endl; // Save the scaled Fisher information Eigenvalues file << mpProblem->getScaledFisherInformationEigenvalues() << std::endl; // Save the scaled Fisher information Eigenvectors file << mpProblem->getScaledFisherInformationEigenvectors() << std::endl << std::endl; if (mpValues->isEnabled()) { // Set up the cross validations table file << "Validations:" << std::endl; file << "Validation Experiment\t Objective Value\tRoot Mean Square\tError Mean\tError Mean Std. Deviation" << std::endl; // Loop over the experiments imax = mpCrossValidations->rowCount(); for (i = 0; i != imax; i++) { file << TO_UTF8(mpCrossValidations->item((int) i, 0)->text()) << "\t"; file << TO_UTF8(mpCrossValidations->item((int) i, 1)->text()) << "\t"; file << TO_UTF8(mpCrossValidations->item((int) i, 2)->text()) << "\t"; file << TO_UTF8(mpCrossValidations->item((int) i, 3)->text()) << "\t"; file << TO_UTF8(mpCrossValidations->item((int) i, 4)->text()) << std::endl; } file << std::endl; } if (mpValues->isEnabled()) { // Set up the fitted values table file << "Validation Fitted Values:" << std::endl; file << "Validation Fitted Value\tObjective Value\tRoot Mean Square\tError Mean\tError Mean Std. Deviation" << std::endl; // Loop over the fitted values objects imax = mpCrossValidationValues->rowCount(); for (i = 0; i != imax; i++) { file << TO_UTF8(mpCrossValidationValues->item((int) i, 0)->text()) << "\t"; file << TO_UTF8(mpCrossValidationValues->item((int) i, 1)->text()) << "\t"; file << TO_UTF8(mpCrossValidationValues->item((int) i, 2)->text()) << "\t"; file << TO_UTF8(mpCrossValidationValues->item((int) i, 3)->text()) << "\t"; file << TO_UTF8(mpCrossValidationValues->item((int) i, 4)->text()) << std::endl; } file << std::endl; } }
void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) { EDA_DRAW_FRAME::LoadSettings( aCfg ); long tmp; ReadHotkeyConfig( SCH_EDIT_FRAME_NAME, g_Schematic_Hokeys_Descr ); wxConfigLoadSetups( aCfg, GetConfigurationSettings() ); SetGridColor( GetLayerColor( LAYER_SCHEMATIC_GRID ) ); SetDrawBgColor( GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) ); SetDefaultBusThickness( aCfg->Read( DefaultBusWidthEntry, DEFAULTBUSTHICKNESS ) ); SetDefaultLineThickness( aCfg->Read( DefaultDrawLineWidthEntry, DEFAULTDRAWLINETHICKNESS ) ); aCfg->Read( ShowHiddenPinsEntry, &m_showAllPins, false ); aCfg->Read( HorzVertLinesOnlyEntry, &m_forceHVLines, true ); aCfg->Read( AutoplaceFieldsEntry, &m_autoplaceFields, true ); aCfg->Read( AutoplaceJustifyEntry, &m_autoplaceJustify, true ); aCfg->Read( AutoplaceAlignEntry, &m_autoplaceAlign, false ); aCfg->Read( FootprintPreviewEntry, &m_footprintPreview, false ); // Load print preview window session settings. aCfg->Read( PreviewFramePositionXEntry, &tmp, -1 ); m_previewPosition.x = (int) tmp; aCfg->Read( PreviewFramePositionYEntry, &tmp, -1 ); m_previewPosition.y = (int) tmp; aCfg->Read( PreviewFrameWidthEntry, &tmp, -1 ); m_previewSize.SetWidth( (int) tmp ); aCfg->Read( PreviewFrameHeightEntry, &tmp, -1 ); m_previewSize.SetHeight( (int) tmp ); // Load print dialog session settings. aCfg->Read( PrintDialogPositionXEntry, &tmp, -1 ); m_printDialogPosition.x = (int) tmp; aCfg->Read( PrintDialogPositionYEntry, &tmp, -1 ); m_printDialogPosition.y = (int) tmp; aCfg->Read( PrintDialogWidthEntry, &tmp, -1 ); m_printDialogSize.SetWidth( (int) tmp ); aCfg->Read( PrintDialogHeightEntry, &tmp, -1 ); m_printDialogSize.SetHeight( (int) tmp ); // Load netlists options: aCfg->Read( SimulatorCommandEntry, &m_simulatorCommand ); // Load find dialog session setting. aCfg->Read( FindDialogPositionXEntry, &tmp, -1 ); m_findDialogPosition.x = (int) tmp; aCfg->Read( FindDialogPositionYEntry, &tmp, -1 ); m_findDialogPosition.y = (int) tmp; aCfg->Read( FindDialogWidthEntry, &tmp, -1 ); m_findDialogSize.SetWidth( (int) tmp ); aCfg->Read( FindDialogHeightEntry, &tmp, -1 ); m_findDialogSize.SetHeight( (int) tmp ); wxASSERT_MSG( m_findReplaceData, wxT( "Find dialog data settings object not created. Bad programmer!" ) ); aCfg->Read( FindReplaceFlagsEntry, &tmp, (long) wxFR_DOWN ); m_findReplaceData->SetFlags( (wxUint32) tmp & ~FR_REPLACE_ITEM_FOUND ); m_findReplaceData->SetFindString( aCfg->Read( FindStringEntry, wxEmptyString ) ); m_findReplaceData->SetReplaceString( aCfg->Read( ReplaceStringEntry, wxEmptyString ) ); // Load the find and replace string history list. for( int i = 0; i < FR_HISTORY_LIST_CNT; ++i ) { wxString tmpHistory; wxString entry; entry.Printf( FindStringHistoryEntry, i ); tmpHistory = aCfg->Read( entry, wxEmptyString ); if( !tmpHistory.IsEmpty() ) m_findStringHistoryList.Add( tmpHistory ); entry.Printf( ReplaceStringHistoryEntry, i ); tmpHistory = aCfg->Read( entry, wxEmptyString ); if( !tmpHistory.IsEmpty() ) m_replaceStringHistoryList.Add( tmpHistory ); } wxString templateFieldNames = aCfg->Read( FieldNamesEntry, wxEmptyString ); if( !templateFieldNames.IsEmpty() ) { TEMPLATE_FIELDNAMES_LEXER lexer( TO_UTF8( templateFieldNames ) ); try { m_TemplateFieldNames.Parse( &lexer ); } catch( const IO_ERROR& DBG( e ) ) { // @todo show error msg DBG( printf( "templatefieldnames parsing error: '%s'\n", TO_UTF8( e.What() ) ); ) } }
bool CQSpecieDM::specieDataChange( UndoSpeciesData *pUndoSpeciesData, const QVariant &value, int column) { switchToWidget(CCopasiUndoCommand::SPECIES); GET_MODEL_OR(pModel, return false); mpSpecies = dynamic_cast<CMetab*>(pUndoSpeciesData->getObject(pModel)); if (mpSpecies == NULL) return false; const CCompartment * pCompartment = NULL; if (column == COL_COMPARTMENT || column == COL_ICONCENTRATION || column == COL_INUMBER) { try { pCompartment = mpSpecies->getCompartment(); } catch (...) {} } if (column == COL_NAME_SPECIES) { mpSpecies->setObjectName(TO_UTF8(value.toString())); pUndoSpeciesData->setCN(mpSpecies->getCN()); } else if (column == COL_COMPARTMENT) { // This must be set first for setInitialConcentration and // setInitialNumber to work correctly. std::string Compartment(TO_UTF8(value.toString())); if (Compartment != pCompartment->getObjectName()) { std::string CompartmentToRemove = mpSpecies->getCompartment()->getObjectName(); if (!(pModel->getCompartments()[Compartment].addMetabolite(mpSpecies))) { QString msg; msg = "Unable to move species '" + FROM_UTF8(mpSpecies->getObjectName()) + "'\n" + "from compartment '" + FROM_UTF8(CompartmentToRemove) + "' to compartment '" + FROM_UTF8(Compartment) + "'\n" + "since a species with that name already exist in the target compartment."; CQMessageBox::information(NULL, "Unable to move Species", msg, QMessageBox::Ok, QMessageBox::Ok); return false; } else { pModel->getCompartments()[CompartmentToRemove].getMetabolites().remove(mpSpecies->getObjectName()); pModel->setCompileFlag(); pModel->initializeMetabolites(); if (mpSpecies && pCompartment) { C_FLOAT64 Factor = 1.0 / pCompartment->getInitialValue(); Factor *= pCompartment->getInitialValue(); mpSpecies->setInitialValue(Factor * pUndoSpeciesData->getINumber()); mpSpecies->setValue(Factor * mpSpecies->getValue()); } emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, mpSpecies->getKey()); emit notifyGUI(ListViews::COMPARTMENT, ListViews::CHANGE, pCompartment->getKey()); } } } else if (column == COL_TYPE_SPECIES) mpSpecies->setStatus((CModelEntity::Status) mItemToType[value.toInt()]); else if (column == COL_ICONCENTRATION) { if (mFlagConc) mpSpecies->setInitialConcentration(value.toDouble()); if (mpSpecies && pCompartment) { const C_FLOAT64 initialValue = CMetab::convertToNumber(pUndoSpeciesData->getIConc(), *pCompartment, *pModel); mpSpecies->setInitialValue(initialValue); } } else if (column == COL_INUMBER) { if (!mFlagConc) mpSpecies->setInitialValue(value.toDouble()); if (mpSpecies && pCompartment) { mpSpecies->setInitialConcentration( CMetab::convertToConcentration(pUndoSpeciesData->getINumber(), *pCompartment, *pModel) ); } } //Save Key std::string key = mpSpecies->getKey(); // ask for refresh this may change the key! QModelIndex index = getIndexFor(mpSpecies, column); emit dataChanged(index, index); if (column == COL_NAME_SPECIES) { emit notifyGUI(ListViews::METABOLITE, ListViews::RENAME, key); } else { emit notifyGUI(ListViews::METABOLITE, ListViews::CHANGE, key); } return true; }
bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles() { wxString msg; bool hasMissingNicks = false; FP_LIB_TABLE* tbl = FootprintLibs(); ReadSchematicNetlist(); if( m_ListCmp == NULL ) return false; LoadProjectFile( m_NetlistFileName.GetFullPath() ); LoadFootprintFiles(); BuildFOOTPRINTS_LISTBOX(); BuildLIBRARY_LISTBOX(); m_ListCmp->Clear(); m_undefinedComponentCnt = 0; if( m_netlist.AnyFootprintsLinked() ) { for( unsigned i = 0; i < m_netlist.GetCount(); i++ ) { COMPONENT* component = m_netlist.GetComponent( i ); if( component->GetFPID().empty() ) continue; if( component->GetFPID().IsLegacy() ) hasMissingNicks = true; } } // Check if footprint links were generated before the footprint library table was implemented. if( hasMissingNicks ) { msg = wxT( "Some of the assigned footprints are legacy entries (are missing lib nicknames). " "Would you like CvPcb to attempt to convert them to the new required FPID format? " "(If you answer no, then these assignments will be cleared out and you will " "have to re-assign these footprints yourself.)" ); if( IsOK( this, msg ) ) { msg.Clear(); try { for( unsigned i = 0; i < m_netlist.GetCount(); i++ ) { COMPONENT* component = m_netlist.GetComponent( i ); if( component->GetFPID().IsLegacy() ) { int guess = guessNickname( tbl, (FPID*) &component->GetFPID() ); switch( guess ) { case 0: DBG(printf("%s: guessed OK ref:%s fpid:%s\n", __func__, TO_UTF8( component->GetReference() ), component->GetFPID().Format().c_str() );) m_modified = true; break; case 1: msg += wxString::Format( _( "Component '%s' footprint '%s' was <b>not found</b> in any library.\n" ), GetChars( component->GetReference() ), GetChars( component->GetFPID().GetFootprintName() ) ); break; case 2: msg += wxString::Format( _( "Component '%s' footprint '%s' was found in <b>multiple</b> libraries.\n" ), GetChars( component->GetReference() ), GetChars( component->GetFPID().GetFootprintName() ) ); break; } } } }
void deleteHostnameRegex(const UnicodeString &us) { deleteHostnameRegexUTF8(TO_UTF8(us)); };
static void write_name_and_type(buffer_t buffer, VALUE name, char type) { SAFE_WRITE(buffer, &type, 1); name = TO_UTF8(name); write_utf8(buffer, name); SAFE_WRITE(buffer, &zero, 1); }
CompartmentDataChangeCommand::CompartmentDataChangeCommand( const QModelIndex& index, const QVariant& value, int role, CQCompartmentDM *pCompartmentDM) : CCopasiUndoCommand("Compartment", COMPARTMENT_DATA_CHANGE, "Change") , mNew(value) , mOld(index.data(Qt::DisplayRole)) , mIndex(index) , mpCompartmentDM(pCompartmentDM) , mRole(role) , mPathIndex() , mpCompartmentUndoData(NULL) { //set the data for UNDO history assert(pCompartmentDM->getDataModel() != NULL); CModel * pModel = pCompartmentDM->getDataModel()->getModel(); assert(pModel != NULL); if (pModel->getCompartments().size() <= (size_t)index.row()) { return; } CCompartment *pCompartment = &pModel->getCompartments()[index.row()]; setKey(pCompartment->getKey()); setName(pCompartment->getObjectName()); setOldValue(TO_UTF8(mOld.toString())); setNewValue(TO_UTF8(mNew.toString())); switch (index.column()) { case 0: setProperty(""); break; case 1: setProperty("Name"); break; case 2: setProperty("Type"); switch (mNew.toInt()) { case 0: setNewValue("fixed"); break; case 1: setNewValue("assignment"); break; case 2: setNewValue("ode"); break; } break; case 3: setProperty("Initial Volume"); // need to store additional undo data to be able to restore // species initial concentrations / patricle numbers mpCompartmentUndoData = new UndoCompartmentData(pCompartment); break; } setText(QString(": Changed compartment %1").arg(getProperty().c_str())); }
void addHostnameRegex(const UnicodeString &us) { addHostnameRegexUTF8(TO_UTF8(us)); };
bool CQOptimizationWidget::saveTask() { COptTask * pTask = dynamic_cast< COptTask * >(mpTask); if (!pTask) return false; saveCommon(); saveMethod(); COptProblem * pProblem = dynamic_cast<COptProblem *>(mpTask->getProblem()); if (!pProblem) return false; // expression if (pProblem->getObjectiveFunction() != mpExpressionEMW->mpExpressionWidget->getExpression()) { if (!pProblem->setObjectiveFunction(mpExpressionEMW->mpExpressionWidget->getExpression())) { CCopasiMessage(CCopasiMessage::ERROR, MCOptimization + 5); return false; } mChanged = true; } if (mpBoxSubtask->currentText() != FROM_UTF8(CCopasiTask::TypeName[pProblem->getSubtaskType()])) { mChanged = true; pProblem->setSubtaskType((CCopasiTask::Type) mSubtaskMap[TO_UTF8(mpBoxSubtask->currentText())]); } if (mpBtnMaximize->isChecked() != pProblem->maximize()) { mChanged = true; pProblem->setMaximize(mpBtnMaximize->isChecked()); } if (mpCheckRandomize->isChecked() != pProblem->getRandomizeStartValues()) { mChanged = true; pProblem->setRandomizeStartValues(mpCheckRandomize->isChecked()); } if (mpCheckStatistics->isChecked() != pProblem->getCalculateStatistics()) { mChanged = true; pProblem->setCalculateStatistics(mpCheckStatistics->isChecked()); } mChanged |= mpParameters->save(NULL, NULL); mChanged |= mpConstraints->save(NULL, NULL); if (mChanged) { assert(CCopasiRootContainer::getDatamodelList()->size() > 0); (*CCopasiRootContainer::getDatamodelList())[0]->changed(); } mChanged = false; return true; }
void CQSpeciesDetail::save() { if (mpMetab == NULL) return; CModel * pModel = const_cast< CModel * >(mpMetab->getModel()); if (pModel == NULL) return; // Compartment if (mpCurrentCompartment != mpMetab->getCompartment()) { QString Compartment = mpComboBoxCompartment->currentText(); std::string CompartmentToRemove = mpMetab->getCompartment()->getObjectName(); if (!pModel->getCompartments()[TO_UTF8(Compartment)].addMetabolite(mpMetab)) { QString msg; msg = "Unable to move species '" + FROM_UTF8(mpMetab->getObjectName()) + "'\n" + "from compartment '" + FROM_UTF8(CompartmentToRemove) + "' to compartment '" + Compartment + "'\n" + "since a species with that name already exist in the target compartment."; CQMessageBox::information(this, "Unable to move Species", msg, QMessageBox::Ok, QMessageBox::Ok); // Revert the changes mpComboBoxCompartment->setCurrentIndex(mpComboBoxCompartment->findText(FROM_UTF8(CompartmentToRemove))); slotCompartmentChanged(mpComboBoxCompartment->currentIndex()); } else { pModel->getCompartments()[CompartmentToRemove].getMetabolites().remove(mpMetab->getObjectName()); pModel->setCompileFlag(); pModel->initializeMetabolites(); protectedNotify(ListViews::COMPARTMENT, ListViews::CHANGE, ""); mChanged = true; } } // Type if (mpMetab->getStatus() != (CModelEntity::Status) mItemToType[mpComboBoxType->currentIndex()]) { mpMetab->setStatus((CModelEntity::Status) mItemToType[mpComboBoxType->currentIndex()]); mChanged = true; } // Initial Concentration and Initial Number switch (mFramework) { case 0: if (mpMetab->getInitialConcentration() != mInitialConcentration) { mpMetab->setInitialConcentration(mInitialConcentration); mChanged = true; } break; case 1: if (mpMetab->getInitialValue() != mInitialNumber) { mpMetab->setInitialValue(mInitialNumber); mChanged = true; } break; } // Expression if (mpMetab->getExpression() != mpExpressionEMW->mpExpressionWidget->getExpression()) { mpMetab->setExpression(mpExpressionEMW->mpExpressionWidget->getExpression()); mChanged = true; } // Initial Expression if ((CModelEntity::Status) mItemToType[mpComboBoxType->currentIndex()] != CModelEntity::ASSIGNMENT) { if (mpBoxUseInitialExpression->isChecked() && mpMetab->getInitialExpression() != (mpInitialExpressionEMW->mpExpressionWidget->getExpression())) { mpMetab->setInitialExpression(mpInitialExpressionEMW->mpExpressionWidget->getExpression()); mChanged = true; } else if (!mpBoxUseInitialExpression->isChecked() && mpMetab->getInitialExpression() != "") { mpMetab->setInitialExpression(""); mChanged = true; } } if (mChanged) { if (mpDataModel) mpDataModel->changed(); protectedNotify(ListViews::METABOLITE, ListViews::CHANGE, mKey); } mChanged = false; }
void CQFittingResult::slotSave(void) { C_INT32 Answer = QMessageBox::No; QString fileName; while (Answer == QMessageBox::No) { fileName = CopasiFileDialog::getSaveFileName(this, "Save File Dialog", QString::null, "TEXT Files (*.txt);;All Files (*.*);;", "Save to"); if (fileName.isEmpty()) return; if (!fileName.endsWith(".txt") && !fileName.endsWith(".")) fileName += ".txt"; fileName = fileName.remove(QRegExp("\\.$")); Answer = checkSelection(fileName); if (Answer == QMessageBox::Cancel) return; } std::ofstream file(utf8ToLocale(TO_UTF8(fileName)).c_str()); if (file.fail()) return; unsigned C_INT32 i, imax; // The global result and statistics file << "Objective Value\tRoot Mean Square\tStandard Deviation" << std::endl; file << mpProblem->getSolutionValue() << "\t"; file << mpProblem->getRMS() << "\t"; file << mpProblem->getStdDeviation() << std::endl; file << "Function Evaluations\tCPU Time [s]\tEvaluations/second [1/s]" << std::endl; const unsigned C_INT32 & FunctionEvaluations = mpProblem->getFunctionEvaluations(); const C_FLOAT64 & ExecutionTime = mpProblem->getExecutionTime(); file << FunctionEvaluations << "\t"; file << ExecutionTime << "\t"; file << FunctionEvaluations / ExecutionTime << std::endl; // Set up the parameters table file << std::endl << "Parameters:" << std::endl; file << "Parameter\tValue\tStd. Deviation\tCoeff. of Variation [%]\tGradient" << std::endl; // Loop over the optimization items const std::vector< COptItem * > & Items = mpProblem->getOptItemList(); const CVector< C_FLOAT64 > & Solutions = mpProblem->getSolutionVariables(); const CVector< C_FLOAT64 > & StdDeviations = mpProblem->getVariableStdDeviations(); const CVector< C_FLOAT64 > & Gradients = mpProblem->getVariableGradients(); imax = Items.size(); if (mpProblem->getFunctionEvaluations() == 0) imax = 0; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; assert(pDataModel != NULL); for (i = 0; i != imax; i++) { const CCopasiObject *pObject = pDataModel->getObject(Items[i]->getObjectCN()); if (pObject) { std::string Experiments = static_cast<CFitItem *>(Items[i])->getExperiments(); if (Experiments != "") Experiments = "; {" + Experiments + "}"; file << pObject->getObjectDisplayName() << Experiments << "\t"; } else file << "Not Found\t"; const C_FLOAT64 & Solution = Solutions[i]; file << Solution << "\t"; const C_FLOAT64 & StdDeviation = StdDeviations[i]; file << StdDeviation << "\t"; file << fabs(100.0 * StdDeviation / Solution) << "\t"; file << Gradients[i] << std::endl; } // Set up the experiments table file << std::endl << "Experiments:" << std::endl; file << "Experiment\tObjective Value\tRoot Mean Square\tError Mean\tError Mean Std. Deviation" << std::endl; // Loop over the experiments const CExperimentSet & Experiments = mpProblem->getExperiementSet(); imax = Experiments.getExperimentCount(); if (mpProblem->getFunctionEvaluations() == 0) imax = 0; for (i = 0; i != imax; i++) { const CExperiment & Experiment = * Experiments.getExperiment(i); file << Experiment.getObjectName() << "\t"; file << Experiment.getObjectiveValue() << "\t"; file << Experiment.getRMS() << "\t"; file << Experiment.getErrorMean() << "\t"; file << Experiment.getErrorMeanSD() << std::endl; } // Set up the fitted values table file << std::endl << "Fitted Values:" << std::endl; file << "Fitted Value\tObjective Value\tRoot Mean Square\tError Mean\tError Mean Std. Deviation" << std::endl; // Loop over the fitted values objects imax = Experiments.getDependentObjects().size(); if (mpProblem->getFunctionEvaluations() == 0) imax = 0; for (i = 0; i != imax; i++) { const CCopasiObject * pObject = Experiments.getDependentObjects()[i]; if (pObject) file << pObject->getObjectDisplayName() << "\t"; else file << "Not Found\t"; file << Experiments.getDependentObjectiveValues()[i] << "\t"; file << Experiments.getDependentRMS()[i] << "\t"; file << Experiments.getDependentErrorMean()[i] << "\t"; file << Experiments.getDependentErrorMeanSD()[i] << std::endl; } file << std::endl; // Save the parameter correlations file << mpProblem->getCorrelations() << std::endl; // Save the Fisher information file << mpProblem->getFisherInformation() << std::endl; }
/** * Function Export_IDF3 * generates IDFv3 compliant board (*.emn) and library (*.emp) * files representing the user's PCB design. */ bool Export_IDF3( BOARD* aPcb, const wxString& aFullFileName, bool aUseThou, double aXRef, double aYRef ) { IDF3_BOARD idfBoard( IDF3::CAD_ELEC ); // Switch the locale to standard C (needed to print floating point numbers) LOCALE_IO toggle; bool ok = true; double scale = MM_PER_IU; // we must scale internal units to mm for IDF IDF3::IDF_UNIT idfUnit; if( aUseThou ) { idfUnit = IDF3::UNIT_THOU; idfBoard.SetUserPrecision( 1 ); } else { idfUnit = IDF3::UNIT_MM; idfBoard.SetUserPrecision( 5 ); } wxFileName brdName = aPcb->GetFileName(); idfBoard.SetUserScale( scale ); idfBoard.SetBoardThickness( aPcb->GetDesignSettings().GetBoardThickness() * scale ); idfBoard.SetBoardName( TO_UTF8( brdName.GetFullName() ) ); idfBoard.SetBoardVersion( 0 ); idfBoard.SetLibraryVersion( 0 ); std::ostringstream ostr; ostr << "KiCad " << TO_UTF8( GetBuildVersion() ); idfBoard.SetIDFSource( ostr.str() ); try { // set up the board reference point idfBoard.SetUserOffset( -aXRef, aYRef ); // Export the board outline idf_export_outline( aPcb, idfBoard ); // Output the drill holes and module (library) data. for( MODULE* module = aPcb->m_Modules; module != 0; module = module->Next() ) idf_export_module( aPcb, module, idfBoard ); if( !idfBoard.WriteFile( aFullFileName, idfUnit, false ) ) { wxString msg; msg << _( "IDF Export Failed:\n" ) << FROM_UTF8( idfBoard.GetError().c_str() ); wxMessageBox( msg ); ok = false; } } catch( const IO_ERROR& ioe ) { wxString msg; msg << _( "IDF Export Failed:\n" ) << ioe.errorText; wxMessageBox( msg ); ok = false; } catch( const std::exception& e ) { wxString msg; msg << _( "IDF Export Failed:\n" ) << FROM_UTF8( e.what() ); wxMessageBox( msg ); ok = false; } return ok; }
static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow_id) { buffer_t buffer = (buffer_t)NUM2LL(rb_ary_entry(extra, 0)); VALUE check_keys = rb_ary_entry(extra, 1); if (TYPE(key) == T_SYMBOL) { // TODO better way to do this... ? key = rb_str_new2(rb_id2name(SYM2ID(key))); } if (TYPE(key) != T_STRING) { buffer_free(buffer); rb_raise(rb_eTypeError, "keys must be strings or symbols"); } if (!allow_id && strcmp("_id", RSTRING_PTR(key)) == 0) { return ST_CONTINUE; } if (check_keys == Qtrue) { int i; if (RSTRING_LEN(key) > 0 && RSTRING_PTR(key)[0] == '$') { buffer_free(buffer); rb_raise(InvalidName, "key must not start with '$'"); } for (i = 0; i < RSTRING_LEN(key); i++) { if (RSTRING_PTR(key)[i] == '.') { buffer_free(buffer); rb_raise(InvalidName, "key must not contain '.'"); } } } switch(TYPE(value)) { case T_BIGNUM: case T_FIXNUM: { if (rb_funcall(value, rb_intern(">"), 1, LL2NUM(9223372036854775807LL)) == Qtrue || rb_funcall(value, rb_intern("<"), 1, LL2NUM(-9223372036854775808LL)) == Qtrue) { buffer_free(buffer); rb_raise(rb_eRangeError, "MongoDB can only handle 8-byte ints"); } if (rb_funcall(value, rb_intern(">"), 1, INT2NUM(2147483647L)) == Qtrue || rb_funcall(value, rb_intern("<"), 1, INT2NUM(-2147483648L)) == Qtrue) { long long ll_value; write_name_and_type(buffer, key, 0x12); ll_value = NUM2LL(value); SAFE_WRITE(buffer, (char*)&ll_value, 8); } else { int int_value; write_name_and_type(buffer, key, 0x10); int_value = NUM2LL(value); SAFE_WRITE(buffer, (char*)&int_value, 4); } break; } case T_TRUE: { write_name_and_type(buffer, key, 0x08); SAFE_WRITE(buffer, &one, 1); break; } case T_FALSE: { write_name_and_type(buffer, key, 0x08); SAFE_WRITE(buffer, &zero, 1); break; } case T_FLOAT: { double d = NUM2DBL(value); write_name_and_type(buffer, key, 0x01); SAFE_WRITE(buffer, (char*)&d, 8); break; } case T_NIL: { write_name_and_type(buffer, key, 0x0A); break; } case T_HASH: { write_name_and_type(buffer, key, 0x03); write_doc(buffer, value, check_keys); break; } case T_ARRAY: { buffer_position length_location, start_position, obj_length; int items, i; VALUE* values; write_name_and_type(buffer, key, 0x04); start_position = buffer_get_position(buffer); // save space for length length_location = buffer_save_space(buffer, 4); if (length_location == -1) { rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c"); } items = RARRAY_LEN(value); values = RARRAY_PTR(value); for(i = 0; i < items; i++) { char* name; VALUE key; INT2STRING(&name, i); key = rb_str_new2(name); write_element(key, values[i], pack_extra(buffer, check_keys)); free(name); } // write null byte and fill in length SAFE_WRITE(buffer, &zero, 1); obj_length = buffer_get_position(buffer) - start_position; SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&obj_length, 4); break; } case T_STRING: { if (strcmp(rb_class2name(RBASIC(value)->klass), "Mongo::Code") == 0) { buffer_position length_location, start_position, total_length; int length; write_name_and_type(buffer, key, 0x0F); start_position = buffer_get_position(buffer); length_location = buffer_save_space(buffer, 4); if (length_location == -1) { rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c"); } length = RSTRING_LEN(value) + 1; SAFE_WRITE(buffer, (char*)&length, 4); SAFE_WRITE(buffer, RSTRING_PTR(value), length - 1); SAFE_WRITE(buffer, &zero, 1); write_doc(buffer, rb_funcall(value, rb_intern("scope"), 0), Qfalse); total_length = buffer_get_position(buffer) - start_position; SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&total_length, 4); break; } else { int length; write_name_and_type(buffer, key, 0x02); value = TO_UTF8(value); length = RSTRING_LEN(value) + 1; SAFE_WRITE(buffer, (char*)&length, 4); write_utf8(buffer, value); SAFE_WRITE(buffer, &zero, 1); break; } } case T_SYMBOL: { const char* str_value = rb_id2name(SYM2ID(value)); int length = strlen(str_value) + 1; write_name_and_type(buffer, key, 0x0E); SAFE_WRITE(buffer, (char*)&length, 4); SAFE_WRITE(buffer, str_value, length); break; } case T_OBJECT: { // TODO there has to be a better way to do these checks... const char* cls = rb_class2name(RBASIC(value)->klass); if (strcmp(cls, "Mongo::Binary") == 0 || strcmp(cls, "ByteBuffer") == 0) { const char subtype = strcmp(cls, "ByteBuffer") ? (const char)FIX2INT(rb_funcall(value, rb_intern("subtype"), 0)) : 2; VALUE string_data = rb_funcall(value, rb_intern("to_s"), 0); int length = RSTRING_LEN(string_data); write_name_and_type(buffer, key, 0x05); if (subtype == 2) { const int other_length = length + 4; SAFE_WRITE(buffer, (const char*)&other_length, 4); SAFE_WRITE(buffer, &subtype, 1); } SAFE_WRITE(buffer, (const char*)&length, 4); if (subtype != 2) { SAFE_WRITE(buffer, &subtype, 1); } SAFE_WRITE(buffer, RSTRING_PTR(string_data), length); break; } if (strcmp(cls, "Mongo::ObjectID") == 0) { VALUE as_array = rb_funcall(value, rb_intern("to_a"), 0); int i; write_name_and_type(buffer, key, 0x07); for (i = 0; i < 12; i++) { char byte = (char)FIX2INT(RARRAY_PTR(as_array)[i]); SAFE_WRITE(buffer, &byte, 1); } break; } if (strcmp(cls, "Mongo::DBRef") == 0) { buffer_position length_location, start_position, obj_length; VALUE ns, oid; write_name_and_type(buffer, key, 0x03); start_position = buffer_get_position(buffer); // save space for length length_location = buffer_save_space(buffer, 4); if (length_location == -1) { rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c"); } ns = rb_funcall(value, rb_intern("namespace"), 0); write_element(rb_str_new2("$ref"), ns, pack_extra(buffer, Qfalse)); oid = rb_funcall(value, rb_intern("object_id"), 0); write_element(rb_str_new2("$id"), oid, pack_extra(buffer, Qfalse)); // write null byte and fill in length SAFE_WRITE(buffer, &zero, 1); obj_length = buffer_get_position(buffer) - start_position; SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&obj_length, 4); break; } } case T_DATA: { // TODO again, is this really the only way to do this? const char* cls = rb_class2name(RBASIC(value)->klass); if (strcmp(cls, "Time") == 0) { double t = NUM2DBL(rb_funcall(value, rb_intern("to_f"), 0)); long long time_since_epoch = (long long)round(t * 1000); write_name_and_type(buffer, key, 0x09); SAFE_WRITE(buffer, (const char*)&time_since_epoch, 8); break; } } case T_REGEXP: { int length = RREGEXP_SRC_LEN(value); char* pattern = (char*)RREGEXP_SRC_PTR(value); long flags = RREGEXP(value)->ptr->options; VALUE has_extra; write_name_and_type(buffer, key, 0x0B); SAFE_WRITE(buffer, pattern, length); SAFE_WRITE(buffer, &zero, 1); if (flags & IGNORECASE) { char ignorecase = 'i'; SAFE_WRITE(buffer, &ignorecase, 1); } if (flags & MULTILINE) { char multiline = 'm'; SAFE_WRITE(buffer, &multiline, 1); } if (flags & EXTENDED) { char extended = 'x'; SAFE_WRITE(buffer, &extended, 1); } has_extra = rb_funcall(value, rb_intern("respond_to?"), 1, rb_str_new2("extra_options_str")); if (TYPE(has_extra) == T_TRUE) { VALUE extra = rb_funcall(value, rb_intern("extra_options_str"), 0); buffer_position old_position = buffer_get_position(buffer); SAFE_WRITE(buffer, RSTRING_PTR(extra), RSTRING_LEN(extra)); qsort(buffer_get_buffer(buffer) + old_position, RSTRING_LEN(extra), sizeof(char), cmp_char); } SAFE_WRITE(buffer, &zero, 1); break; } default: { buffer_free(buffer); rb_raise(rb_eTypeError, "no c encoder for this type yet (%d)", TYPE(value)); break; } } return ST_CONTINUE; }
/** * Function WriteHotkeyConfig * Store the current hotkey list * It is stored using the standard wxConfig mechanism or a file. * * @param aDescList = pointer to the current hotkey list. * @param aFullFileName = a wxString pointer to a full file name. * if NULL, use the standard wxConfig mechanism (default) * the output format is: shortcut "key" "function" * lines starting with # are comments */ int EDA_BASE_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, wxString* aFullFileName ) { wxString msg; wxString keyname, infokey; msg = wxT( "$hotkey list\n" ); // Print the current hotkey list EDA_HOTKEY** list; for( ; aDescList->m_HK_InfoList != NULL; aDescList++ ) { if( aDescList->m_Comment ) { msg += wxT( "# " ); msg += wxString( aDescList->m_Comment ); msg += wxT( "\n" ); } msg += *aDescList->m_SectionTag; msg += wxT( "\n" ); list = aDescList->m_HK_InfoList; for( ; *list != NULL; list++ ) { EDA_HOTKEY* hk_decr = *list; msg += wxT( "shortcut " ); keyname = KeyNameFromKeyCode( hk_decr->m_KeyCode ); AddDelimiterString( keyname ); infokey = hk_decr->m_InfoMsg; AddDelimiterString( infokey ); msg += keyname + wxT( ": " ) + infokey + wxT( "\n" ); } } msg += wxT( "$Endlist\n" ); if( aFullFileName ) { FILE* file = wxFopen( *aFullFileName, wxT( "wt" ) ); if( file ) { fputs( TO_UTF8( msg ), file ); fclose( file ); } else { msg.Printf( wxT( "Unable to write file %s" ), GetChars( *aFullFileName ) ); return 0; } } else { wxConfig config( m_FrameName ); config.Write( HOTKEYS_CONFIG_KEY, msg ); } return 1; }
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event ) { if( !copyPanelToSelectedField() ) return; // test if reference prefix is acceptable if( !SCH_COMPONENT::IsReferenceStringValid( m_FieldsBuf[REFERENCE].GetText() ) ) { DisplayError( NULL, _( "Illegal reference prefix. A reference must start by a letter" ) ); return; } /* Note: this code is now (2010-dec-04) not used, because the value field is no more editable * because changing the value is equivalent to create a new component or alias. * This is now handled in libedit main frame, and no more in this dialog * but this code is not removed, just in case */ /* If a new name entered in the VALUE field, that it not an existing alias name * or root alias of the component */ wxString newvalue = m_FieldsBuf[VALUE].GetText(); if( m_libEntry->HasAlias( newvalue ) && !m_libEntry->GetAlias( newvalue )->IsRoot() ) { wxString msg = wxString::Format( _( "A new name is entered for this component\n" "An alias %s already exists!\n" "Cannot update this component" ), GetChars( newvalue ) ); DisplayError( this, msg ); return; } /* End unused code */ // save old cmp in undo list m_parent->SaveCopyInUndoList( m_libEntry, IS_CHANGED ); // delete any fields with no name or no value before we copy all of m_FieldsBuf // back into the component for( unsigned i = MANDATORY_FIELDS; i < m_FieldsBuf.size(); ) { if( m_FieldsBuf[i].GetName().IsEmpty() || m_FieldsBuf[i].GetText().IsEmpty() ) { m_FieldsBuf.erase( m_FieldsBuf.begin() + i ); continue; } ++i; } #if defined(DEBUG) for( unsigned i=0; i<m_FieldsBuf.size(); ++i ) { printf( "save[%d].name:'%s' value:'%s'\n", i, TO_UTF8( m_FieldsBuf[i].GetName() ), TO_UTF8( m_FieldsBuf[i].GetText() ) ); } #endif // copy all the fields back, fully replacing any previous fields m_libEntry->SetFields( m_FieldsBuf ); // We need to keep the name and the value the same at the moment! SetName( m_libEntry->GetValueField().GetText() ); m_parent->OnModify(); EndModal( 0 ); }