Commit d6af27a3 authored by charras's avatar charras
Browse files

eeschema: enforce time stamp control and repairs bad time stamps in annotation.

parent b9ba67c8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4,6 +4,12 @@ KiCad ChangeLog 2009
Please add newer entries at the top, list the date and your name with
email address.

2009-apr-25 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
++ Eeschema:
    When annotating: tests and repairs bad (duplicated) time stamps.
    Can be found in old schematics or converted from others tools ...

2009-apr-24 UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
++Pcbnew:
+37 −4
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDisplayName</key>
	<string>cvpcb</string>
	<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeIconFile</key>
			<string>cvpcb_doc.icns</string>
			<key>CFBundleTypeExtensions</key>
			<array>
				<string>net</string>
			</array>
			<key>CFBundleTypeName</key>
			<string>cvpcb document</string>
			<key>LSHandlerRank</key>
			<string>Owner</string>
		</dict>
	</array>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleExecutable</key>
	<string>cvpcb</string>
	<key>CFBundleGetInfoString</key>
	<string></string>
	<key>CFBundleIconFile</key>
	<string>cvpcb.icns</string>
	<key>CFBundleIdentifier</key>
	<string>org.kicad-eda.cvpcb</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleLongVersionString</key>
	<string></string>
	<key>CFBundleName</key>
	<string>Cvpcb</string>
	<string></string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string></string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string></string>
	<key>CSResourcesFileMapped</key>
	<true/>
	<key>LSRequiresCarbon</key>
	<true/>
	<key>NSHumanReadableCopyright</key>
	<string></string>
</dict>
</plist>

cvpcb/cvpcb_doc.icns

0 → 100644
+113 KiB

File added.

No diff preview for this file type.

+27 −5
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDisplayName</key>
	<array/>
	<key>CFBundleDocumentTypes</key>
	<array>
		<dict>
@@ -12,18 +10,42 @@
				<string>sch</string>
			</array>
			<key>CFBundleTypeIconFile</key>
			<string>file_sch.icns</string>
			<string>eeschema_doc.icns</string>
			<key>CFBundleTypeName</key>
			<string>eeschema document</string>
			<key>LSHandlerRank</key>
			<string>Owner</string>
		</dict>
	</array>
	<key>CFBundleDevelopmentRegion</key>
	<string>English</string>
	<key>CFBundleExecutable</key>
	<string>eeschema</string>
	<key>CFBundleGetInfoString</key>
	<string></string>
	<key>CFBundleIconFile</key>
	<string>eeschema.icns</string>
	<key>CFBundleIdentifier</key>
	<string>org.kicad-eda.eeschema</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleLongVersionString</key>
	<string></string>
	<key>CFBundleName</key>
	<string>Schematics</string>
	<string></string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string></string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string></string>
	<key>CSResourcesFileMapped</key>
	<true/>
	<key>LSRequiresCarbon</key>
	<true/>
	<key>NSHumanReadableCopyright</key>
	<string></string>
</dict>
</plist>
+170 −35
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ int GetLastReferenceNumber( int aObjet,
                                    std::vector <OBJ_CMP_TO_LIST>& aComponentsList );
static int  ExistUnit( int aObjet, int aUnit,
                       std::vector <OBJ_CMP_TO_LIST>& aComponentsList );
static int  ReplaceDuplicatedTimeStamps();


/******************************************************/
@@ -175,6 +176,21 @@ static bool AnnotateByValue( const OBJ_CMP_TO_LIST& item1, const OBJ_CMP_TO_LIST
}


/*****************************************************************************
* qsort function to annotate items by value
*  Components are sorted by time stamp
*****************************************************************************/
static bool SortByTimeStamp( const OBJ_CMP_TO_LIST& item1, const OBJ_CMP_TO_LIST& item2 )
{
    int ii = item1.m_SheetPath.Cmp( item2.m_SheetPath );

    if( ii == 0 )
        ii = item1.m_TimeStamp - item2.m_TimeStamp;

    return ii < 0;
}


/**************************************************************************************/
void WinEDA_SchematicFrame::DeleteAnnotation( bool aCurrentSheetOnly, bool aRedraw )
/**************************************************************************************/
@@ -237,16 +253,33 @@ void WinEDA_SchematicFrame::DeleteAnnotation( bool aCurrentSheetOnly, bool aRedr
*                     1 = annotate by sorting Y position,
*                     2 = annotate by sorting value
* @param resetAnnotation : true = remove previous annotation false = anotate new components only
* @param repairsTimestamps : true = test for duplicate times stamps and replace duplicated
*                   Note: this option could change previous annotation, because time stamps are used to handle annotation
*                       mainly in complex hierarchies.
*****************************************************************************/
void AnnotateComponents( WinEDA_SchematicFrame* parent,
                         bool                   annotateSchematic,
                         int                    sortOption,
                         bool                   resetAnnotation )
                         bool                   resetAnnotation,
                         bool                   repairsTimestamps )
{
    std::vector <OBJ_CMP_TO_LIST> ComponentsList;

    wxBusyCursor dummy;

    // Test and replace duplicte time stamps
    // duplicate can happen with old schematics, or schematic conversions or manual editions of files ...
    if( repairsTimestamps )
    {
        int ireplacecount = ReplaceDuplicatedTimeStamps();
        if ( ireplacecount )
        {
            wxString msg;
            msg.Printf(_("%d Duplicate Time stamps replaced"), ireplacecount);
            DisplayInfoMessage( NULL, msg, 2);
        }
    }

    /* If it is an annotation for all the components, reset previous
     * annotation: */
    if( resetAnnotation )
@@ -301,8 +334,10 @@ void AnnotateComponents( WinEDA_SchematicFrame* parent,


/*******************************************************************************************************/
int AddComponentsInSheetToList(  std::vector <OBJ_CMP_TO_LIST>& aComponentsList, DrawSheetPath* aSheet )
int AddComponentsInSheetToList(  std::vector <OBJ_CMP_TO_LIST>& aComponentsList,
                                 DrawSheetPath*                 aSheet )
/********************************************************************************************************/

/** function AddComponentsInSheetToList()
 * Add a OBJ_CMP_TO_LIST object in aComponentsList for each component found in sheet
 * @param aComponentsList = a std::vector list to fill
@@ -781,5 +816,105 @@ int CheckAnnotate( WinEDA_SchematicFrame* frame, bool oneSheetOnly )
        }
    }

    // count the duplicated time stamps
    sort( ComponentsList.begin(), ComponentsList.end(), SortByTimeStamp );
    for( int ii = 0; (ii < imax) && (error < 4); ii++ )
    {
        if( (ComponentsList[ii].m_TimeStamp != ComponentsList[ii + 1].m_TimeStamp)
           || ( ComponentsList[ii].m_SheetPath != ComponentsList[ii + 1].m_SheetPath ) )
            continue;

        /* Same time stamp found.  */
        wxString nextcmpref;
        wxString full_path;
        full_path.Printf( wxT( "%s%8.8X" ),
                          ComponentsList[ii].m_SheetPath.Path().GetData(),
                          ComponentsList[ii].m_TimeStamp );
        cmpref     = CONV_FROM_UTF8( ComponentsList[ii].m_Reference );
        nextcmpref = CONV_FROM_UTF8( ComponentsList[ii + 1].m_Reference );
        msg.Printf( _( "duplicate time stamp (%s) for %s%d and %s%d" ),
                    full_path.GetData(),
                    cmpref.GetData(), ComponentsList[ii].m_NumRef,
                    nextcmpref.GetData(), ComponentsList[ii + 1].m_NumRef );
        DisplayError( frame, msg );
        error++;
    }

    return error;
}


/***********************************************
 * function to sort sch_items by time stamp
 ************************************************/
static bool SortItemByTimeStamp( const SCH_ITEM* item1, const SCH_ITEM* item2 )
{
    int ii = item1->m_TimeStamp - item2->m_TimeStamp;

    /* if same time stamp, compare type, in order to have
    *  first : component
    *  after : sheet
    * because this is the first item that have its time stamp changed
    * and changing the time stamp of a sheet can loose annotation
    */

    if( ii == 0 && ( item1->Type() != item2->Type()) )
        if ( item1->Type() == DRAW_SHEET_STRUCT_TYPE )
            ii = -1;

    return ii < 0;
}


/** Function ReplaceDuplicatedTimeStamps
 * Search for duplicate time stamps in the whole hierarchy, and replace duplicae by new time stamps
 */
int ReplaceDuplicatedTimeStamps()
{
    /* Build the whole screen list */
    EDA_ScreenList ScreenList;

    /* Build the list of items with time stamps (components and sheets)
     * note: if all items have a different time stamp, this ensure also different paths in complex hierarchy
     * this is the reason we have differant time stamps for components AND sheets
     */
    std::vector <SCH_ITEM*> itemlist;
    SCH_SCREEN*             screen;
    SCH_ITEM* item;
    for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
    {
        item = screen->EEDrawList;
        while( item )
        {
            if( (item->Type() == DRAW_SHEET_STRUCT_TYPE)
               ||  (item->Type() == TYPE_SCH_COMPONENT) )
                itemlist.push_back( item );

            item = item->Next();
        }
    }

    // Test and replace duplicated time stamps

    int imax     = itemlist.size() - 1;
    int errcount = 0;
    sort( itemlist.begin(), itemlist.end(), SortItemByTimeStamp );
    for( int ii = 0; ii < imax; ii++ )
    {
        item = itemlist[ii];
        SCH_ITEM* nextitem = itemlist[ii + 1];
        if( item->m_TimeStamp == nextitem->m_TimeStamp )
        {
            errcount++;
            // for a component, update its Time stamp and its paths (m_PathsAndReferences field)
            if (item->Type() == TYPE_SCH_COMPONENT )
                ((SCH_COMPONENT*) item)->SetTimeStamp( GetTimeStamp());
            // for a sheet, update only its time stamp (annotation of its components will be lost)
            // TODO: see how to change sheet paths for its cmp list (can be possible in most cases)
            else
                item->m_TimeStamp = GetTimeStamp();
        }
    }

    return errcount;
}
Loading