diff --git a/common/wxwineda.cpp b/common/wxwineda.cpp index 7644891a93..48b1a20905 100644 --- a/common/wxwineda.cpp +++ b/common/wxwineda.cpp @@ -424,7 +424,7 @@ WinEDA_DFloatValueCtrl::WinEDA_DFloatValueCtrl( wxWindow* parent, BoxSizer->Add( m_Text, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 ); - buffer.Printf( wxT( "%lf" ), m_Value ); + buffer.Printf( wxT( "%f" ), m_Value ); m_ValueCtrl = new wxTextCtrl( parent, -1, buffer ); BoxSizer->Add( m_ValueCtrl, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); @@ -453,7 +453,7 @@ void WinEDA_DFloatValueCtrl::SetValue( double new_value ) m_Value = new_value; - buffer.Printf( wxT( "%lf" ), m_Value ); + buffer.Printf( wxT( "%f" ), m_Value ); m_ValueCtrl->SetValue( buffer ); } diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index c3aec359e3..9bdff754ad 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -26,12 +26,12 @@ set(EESCHEMA_SRCS class_netlist_object.cpp class_pin.cpp class_sch_cmp_field.cpp + class_sch_component.cpp class_schematic_items.cpp class_sch_screen.cpp class_text-label.cpp classes_body_items.cpp cleanup.cpp - component_class.cpp controle.cpp cross-probing.cpp dangling_ends.cpp @@ -73,7 +73,6 @@ set(EESCHEMA_SRCS erc.cpp files-io.cpp find.cpp - geometric_transforms.cpp getpart.cpp hierarch.cpp hotkeys.cpp @@ -94,6 +93,7 @@ set(EESCHEMA_SRCS netlist.cpp onleftclick.cpp onrightclick.cpp + operations_on_items_lists.cpp pinedit.cpp # pinedit-dialog.cpp plot.cpp diff --git a/eeschema/block.cpp b/eeschema/block.cpp index ea406f2208..783433778b 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -21,16 +21,14 @@ /* Variables Locales */ // Imported functions: -void MoveItemsInList( SCH_SCREEN* aScreen, PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); +void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center ); -void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& Center ); +void DeleteItemsInList( WinEDA_DrawPanel* panel, PICKED_ITEMS_LIST& aItemsList ); +void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); /* Fonctions exportees */ -void DeleteItemsInList( WinEDA_DrawPanel* panel, - PICKED_ITEMS_LIST& aItemsList ); /* Fonctions Locales */ -static void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); static void CollectStructsToDrag( SCH_SCREEN* screen ); static void AddPickedItem( SCH_SCREEN* screen, wxPoint aPosition ); static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem, @@ -140,7 +138,7 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC ) SaveCopyInUndoList( block->m_ItemsSelection, UR_MOVED, block->m_MoveVector ); - MoveItemsInList( GetScreen(), block->m_ItemsSelection, block->m_MoveVector ); + MoveItemsInList( block->m_ItemsSelection, block->m_MoveVector ); block->ClearItemsList(); break; @@ -287,7 +285,7 @@ int WinEDA_SchematicFrame::HandleBlockEnd( wxDC* DC ) { wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition; SaveStructListForPaste( block->m_ItemsSelection ); - MoveItemsInList( GetScreen(), g_BlockSaveDataList.m_ItemsSelection, move_vector); + MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection, move_vector); ii = -1; } block->ClearItemsList(); @@ -409,7 +407,7 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC ) { wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition; SaveStructListForPaste( block->m_ItemsSelection ); - MoveItemsInList( GetScreen(), g_BlockSaveDataList.m_ItemsSelection, move_vector ); + MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection, move_vector ); ii = -1; } break; @@ -500,107 +498,6 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, } - -/*****************************************************************************/ -void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ) -/*****************************************************************************/ - -/* Routine to copy a new entity of an object for each object in list and reposition it. - * Return the new created object list in aItemsList - */ -{ - SCH_ITEM* newitem; - - if( aItemsList.GetCount() == 0 ) - return; - - for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) - { - newitem = DuplicateStruct( (SCH_ITEM*) aItemsList.GetItemData( ii ) ); - aItemsList.SetItem( newitem, ii ); - aItemsList.SetItemStatus( UR_NEW, ii ); - { - switch( newitem->Type() ) - { - case DRAW_POLYLINE_STRUCT_TYPE: - case DRAW_JUNCTION_STRUCT_TYPE: - case DRAW_SEGMENT_STRUCT_TYPE: - case DRAW_BUSENTRY_STRUCT_TYPE: - case TYPE_SCH_TEXT: - case TYPE_SCH_LABEL: - case TYPE_SCH_GLOBALLABEL: - case TYPE_SCH_HIERLABEL: - case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE: - case DRAW_MARKER_STRUCT_TYPE: - case DRAW_NOCONNECT_STRUCT_TYPE: - default: - break; - - case DRAW_SHEET_STRUCT_TYPE: - { - DrawSheetStruct* sheet = (DrawSheetStruct*) newitem; - sheet->m_TimeStamp = GetTimeStamp(); - sheet->SetSon( NULL ); - break; - } - - case TYPE_SCH_COMPONENT: - ( (SCH_COMPONENT*) newitem )->m_TimeStamp = GetTimeStamp(); - ( (SCH_COMPONENT*) newitem )->ClearAnnotation( NULL ); - break; - } - - SetaParent( newitem, screen ); - newitem->SetNext( screen->EEDrawList ); - screen->EEDrawList = newitem; - } - } - - MoveItemsInList( screen, aItemsList, aMoveVector ); -} - - -/*********************************************************************************/ -void DeleteStruct( WinEDA_DrawPanel* panel, wxDC* DC, SCH_ITEM* DrawStruct ) -/*********************************************************************************/ - -/* Routine to delete an object from global drawing object list. - * Object is put in Undo list - */ -{ - SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen(); - WinEDA_SchematicFrame* frame = (WinEDA_SchematicFrame*) panel->m_Parent; - - if( !DrawStruct ) - return; - - if( DrawStruct->Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) - { - /* Cette stucture est rattachee a une feuille, et n'est pas - * accessible par la liste globale directement */ - frame->SaveCopyInUndoList( (SCH_ITEM*)( (Hierarchical_PIN_Sheet_Struct - *) DrawStruct )->GetParent(), - UR_CHANGED ); - frame->DeleteSheetLabel( DC ? true : false, - (Hierarchical_PIN_Sheet_Struct*) DrawStruct ); - return; - } - - else /* structure classique */ - { - screen->RemoveFromDrawList( DrawStruct ); - - panel->PostDirtyRect( DrawStruct->GetBoundingBox() ); - - /* Unlink the structure */ - DrawStruct->SetNext( 0 ); - DrawStruct->SetBack( 0 ); // Only one struct -> no link - - frame->SaveCopyInUndoList( DrawStruct, UR_DELETED ); - } -} - - /*****************************************************************/ void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList ) /*****************************************************************/ @@ -664,7 +561,7 @@ void WinEDA_SchematicFrame::PasteListOfItems( wxDC* DC ) SaveCopyInUndoList( picklist, UR_NEW ); - MoveItemsInList( GetScreen(), picklist, GetScreen()->m_BlockLocate.m_MoveVector ); + MoveItemsInList( picklist, GetScreen()->m_BlockLocate.m_MoveVector ); /* clear .m_Flags member for all items */ for( Struct = GetScreen()->EEDrawList; Struct != NULL; Struct = Struct->Next() ) @@ -676,131 +573,6 @@ void WinEDA_SchematicFrame::PasteListOfItems( wxDC* DC ) } -/** function DeleteItemsInList - * delete schematic items in aItemsList - * deleted items are put in undo list - */ -void DeleteItemsInList( WinEDA_DrawPanel* panel, PICKED_ITEMS_LIST& aItemsList ) -{ - SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen(); - WinEDA_SchematicFrame* frame = (WinEDA_SchematicFrame*) panel->m_Parent; - PICKED_ITEMS_LIST itemsList; - ITEM_PICKER itemWrapper; - - for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) - { - SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetItemData( ii ); - itemWrapper.m_Item = item; - itemWrapper.m_UndoRedoStatus = UR_DELETED; - if( item->Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) - { - /* this item is depending on a sheet, and is not in global list */ - wxMessageBox( wxT( - "DeleteItemsInList() err: unexpected DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE" ) ); -#if 0 - Hierarchical_PIN_Sheet_Struct* pinlabel = (Hierarchical_PIN_Sheet_Struct*) item; - frame->DeleteSheetLabel( false, pinlabel->m_Parent ); - itemWrapper.m_Item = pinlabel->m_Parent; - itemWrapper.m_UndoRedoStatus = UR_CHANGED; - itemsList.PushItem( itemWrapper ); -#endif - } - else - { - screen->RemoveFromDrawList( item ); - - /* Unlink the structure */ - item->SetNext( 0 ); - item->SetBack( 0 ); - itemsList.PushItem( itemWrapper ); - } - } - - frame->SaveCopyInUndoList( itemsList, UR_DELETED ); -} - - -/************************************************************/ -SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct ) -/************************************************************/ - -/* Routine to create a new copy of given struct. - * The new object is not put in draw list (not linked) - */ -{ - SCH_ITEM* NewDrawStruct = NULL; - - if( DrawStruct == NULL ) - { - DisplayError( NULL, wxT( "DuplicateStruct error: NULL struct" ) ); - return NULL; - } - - switch( DrawStruct->Type() ) - { - case DRAW_POLYLINE_STRUCT_TYPE: - NewDrawStruct = ( (DrawPolylineStruct*) DrawStruct )->GenCopy(); - break; - - case DRAW_SEGMENT_STRUCT_TYPE: - NewDrawStruct = ( (EDA_DrawLineStruct*) DrawStruct )->GenCopy(); - break; - - case DRAW_BUSENTRY_STRUCT_TYPE: - NewDrawStruct = ( (DrawBusEntryStruct*) DrawStruct )->GenCopy(); - break; - - case DRAW_JUNCTION_STRUCT_TYPE: - NewDrawStruct = ( (DrawJunctionStruct*) DrawStruct )->GenCopy(); - break; - - case DRAW_MARKER_STRUCT_TYPE: - NewDrawStruct = ( (MARKER_SCH*) DrawStruct )->GenCopy(); - break; - - case DRAW_NOCONNECT_STRUCT_TYPE: - NewDrawStruct = ( (DrawNoConnectStruct*) DrawStruct )->GenCopy(); - break; - - case TYPE_SCH_TEXT: - NewDrawStruct = ( (SCH_TEXT*) DrawStruct )->GenCopy(); - break; - - case TYPE_SCH_LABEL: - NewDrawStruct = ( (SCH_LABEL*) DrawStruct )->GenCopy(); - break; - - case TYPE_SCH_HIERLABEL: - NewDrawStruct = ( (SCH_HIERLABEL*) DrawStruct )->GenCopy(); - break; - - case TYPE_SCH_GLOBALLABEL: - NewDrawStruct = ( (SCH_GLOBALLABEL*) DrawStruct )->GenCopy(); - break; - - case TYPE_SCH_COMPONENT: - NewDrawStruct = ( (SCH_COMPONENT*) DrawStruct )->GenCopy(); - break; - - case DRAW_SHEET_STRUCT_TYPE: - NewDrawStruct = ( (DrawSheetStruct*) DrawStruct )->GenCopy(); - break; - - default: - { - wxString msg; - msg << wxT( "DuplicateStruct error: unexpected StructType " ) << - DrawStruct->Type() << wxT( " " ) << DrawStruct->GetClass(); - DisplayError( NULL, msg ); - } - break; - } - - NewDrawStruct->m_Image = DrawStruct; - return NewDrawStruct; -} - - /****************************************************/ static void CollectStructsToDrag( SCH_SCREEN* screen ) /****************************************************/ diff --git a/eeschema/class_drawsheet.cpp b/eeschema/class_drawsheet.cpp index 88e815c933..99a1ef9101 100644 --- a/eeschema/class_drawsheet.cpp +++ b/eeschema/class_drawsheet.cpp @@ -705,6 +705,27 @@ void DrawSheetStruct::DisplayInfo( WinEDA_DrawFrame* frame ) } +/** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ +void DrawSheetStruct::Mirror_Y(int aYaxis_position) +{ + m_Pos.x -= aYaxis_position; + NEGATE( m_Pos.x ); + m_Pos.x += aYaxis_position; + + m_Pos.x -= m_Size.x; + + Hierarchical_PIN_Sheet_Struct* label = m_Label; + while( label != NULL ) + { + label->Mirror_Y( aYaxis_position ); + label = label->Next(); + } +} + + #if defined(DEBUG) void DrawSheetStruct::Show( int nestLevel, std::ostream& os ) { diff --git a/eeschema/class_drawsheet.h b/eeschema/class_drawsheet.h index 11cecba823..fc55f073a3 100644 --- a/eeschema/class_drawsheet.h +++ b/eeschema/class_drawsheet.h @@ -70,6 +70,28 @@ public: * @param Pos = Position of the shape */ void CreateGraphicShape( std::vector & aCorner_list, const wxPoint& Pos ); + + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) + { + m_Edge = m_Edge ? 0 : 1; + m_Pos.x -= aYaxis_position; + NEGATE( m_Pos.x ); + m_Pos.x += aYaxis_position; + } }; @@ -224,6 +246,28 @@ public: //to remove a sheet, just delete it //-- the destructor should take care of everything else. + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + Hierarchical_PIN_Sheet_Struct* label = m_Label; + while( label != NULL ) + { + label->Move( aMoveVector ); + label = label->Next(); + } + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position); + #if defined (DEBUG) // comment inherited by Doxygen from Base_Struct diff --git a/eeschema/class_marker_sch.h b/eeschema/class_marker_sch.h index 955251da2e..521bf575e3 100644 --- a/eeschema/class_marker_sch.h +++ b/eeschema/class_marker_sch.h @@ -77,6 +77,27 @@ public: virtual EDA_Rect GetBoundingBox(); + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) + { + m_Pos.x -= aYaxis_position; + m_Pos.x = - m_Pos.x; + m_Pos.x += aYaxis_position; + } + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); #endif diff --git a/eeschema/class_sch_cmp_field.h b/eeschema/class_sch_cmp_field.h index 0549e46666..f19f243ba1 100644 --- a/eeschema/class_sch_cmp_field.h +++ b/eeschema/class_sch_cmp_field.h @@ -78,6 +78,28 @@ public: * @return bool - true if success writing else false. */ bool Save( FILE* aFile ) const; + + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) + { + /* Do Nothing: fields are never mirrored alone. + * they are moved when the parent component is mirrored + * this function is only needed by the virtual pure function of the master class + */ + } }; diff --git a/eeschema/component_class.cpp b/eeschema/class_sch_component.cpp similarity index 97% rename from eeschema/component_class.cpp rename to eeschema/class_sch_component.cpp index 7ff38b28d2..46fa6f88e1 100644 --- a/eeschema/component_class.cpp +++ b/eeschema/class_sch_component.cpp @@ -1,12 +1,11 @@ -/***********************************************************************/ -/* component_class.cpp : handle the class SCH_COMPONENT */ -/***********************************************************************/ +/**************************************************************/ +/* class_sch_component.cpp : handle the class SCH_COMPONENT */ +/**************************************************************/ #include "fctsys.h" #include "class_drawpanel.h" #include "gr_basic.h" #include "common.h" -#include "confirm.h" #include "program.h" #include "libcmp.h" #include "general.h" @@ -14,14 +13,8 @@ #include "protos.h" -#include #include -#include "component_class.h" - - -WX_DEFINE_OBJARRAY( ArrayOfSheetLists ); - /* Local variables */ static EDA_LibComponentStruct* DummyCmp; @@ -148,6 +141,7 @@ void DrawLibPartAux( WinEDA_DrawPanel* panel, wxDC* DC, } + /*******************************************************************/ SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) : SCH_ITEM( aParent, TYPE_SCH_COMPONENT ) @@ -797,7 +791,7 @@ void SCH_COMPONENT::SetRotationMiroir( int type_rotate ) default: Transform = FALSE; - DisplayError( NULL, wxT( "SetRotateMiroir() error: ill value" ) ); + wxMessageBox( wxT( "SetRotateMiroir() error: ill value" ) ); break; } @@ -873,7 +867,7 @@ int SCH_COMPONENT::GetRotationMiroir() } // Error: orientation not found in list (should not happen) - DisplayError(NULL, wxT("Component orientation matrix internal error") ); + wxMessageBox(wxT("Component orientation matrix internal error") ); memcpy( m_Transform, ComponentMatOrient, sizeof( ComponentMatOrient ) ); return CMP_NORMAL; } @@ -1093,3 +1087,23 @@ void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame ) DARKCYAN ); } } + +/** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ +void SCH_COMPONENT::Mirror_Y(int aYaxis_position) +{ + int dx = m_Pos.x; + SetRotationMiroir( CMP_MIROIR_Y ); + m_Pos.x -= aYaxis_position; + NEGATE( m_Pos.x ); + m_Pos.x += aYaxis_position; + dx -= m_Pos.x; // dx,0 is the move vector for this transform + + for( int ii = 0; ii < GetFieldCount(); ii++ ) + { + /* move the fields to the new position because the component itself has moved */ + GetField( ii )->m_Pos.x -= dx; + } +} diff --git a/eeschema/component_class.h b/eeschema/class_sch_component.h similarity index 94% rename from eeschema/component_class.h rename to eeschema/class_sch_component.h index 47cda596a0..6e8b929cdf 100644 --- a/eeschema/component_class.h +++ b/eeschema/class_sch_component.h @@ -285,7 +285,25 @@ public: */ virtual int GetPenSize( ) { return 0; } -#if defined (DEBUG) + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + for( int ii = 0; ii < GetFieldCount(); ii++ ) + GetField( ii )->Move(aMoveVector); + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position); + + #if defined (DEBUG) /** * Function Show diff --git a/eeschema/class_schematic_items.h b/eeschema/class_schematic_items.h index 7373a31859..cdb36a170f 100644 --- a/eeschema/class_schematic_items.h +++ b/eeschema/class_schematic_items.h @@ -69,6 +69,33 @@ public: */ virtual int GetPenSize( ); + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + if( (m_Flags & STARTPOINT) == 0 ) + m_Start += aMoveVector; + if( (m_Flags & ENDPOINT) == 0 ) + m_End += aMoveVector; + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) + { + m_Start.x -= aYaxis_position; + NEGATE( m_Start.x ); + m_Start.x += aYaxis_position; + m_End.x -= aYaxis_position; + NEGATE( m_End.x ); + m_End.x += aYaxis_position; + } + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); #endif @@ -116,6 +143,26 @@ public: bool HitTest( const wxPoint& aPosRef ); EDA_Rect GetBoundingBox(); + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) + { + m_Pos.x -= aYaxis_position; + NEGATE( m_Pos.x ); + m_Pos.x += aYaxis_position; + } }; @@ -162,6 +209,27 @@ public: */ virtual int GetPenSize( ); + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) + { + m_Pos.x -= aYaxis_position; + NEGATE( m_Pos.x ); + m_Pos.x += aYaxis_position; + NEGATE( m_Size.x ); + } }; class DrawPolylineStruct : public SCH_ITEM /* Polyligne (serie de segments) */ @@ -213,6 +281,29 @@ public: */ virtual int GetPenSize( ); + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + for( unsigned ii = 0; ii < GetCornerCount(); ii++ ) + m_PolyPoints[ii] += aMoveVector; + } + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) + { + for( unsigned ii = 0; ii < GetCornerCount(); ii++ ) + { + m_PolyPoints[ii].x -= aYaxis_position; + NEGATE( m_PolyPoints[ii].x ); + m_PolyPoints[ii].x = aYaxis_position; + } + } }; @@ -257,6 +348,27 @@ public: */ bool Save( FILE* aFile ) const; + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) + { + m_Pos.x -= aYaxis_position; + NEGATE( m_Pos.x ); + m_Pos.x += aYaxis_position; + } + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); #endif diff --git a/eeschema/class_text-label.cpp b/eeschema/class_text-label.cpp index 9005921552..76d007d40f 100644 --- a/eeschema/class_text-label.cpp +++ b/eeschema/class_text-label.cpp @@ -186,6 +186,31 @@ wxPoint SCH_LABEL::GetSchematicTextOffset() } +/** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ +void SCH_TEXT::Mirror_Y(int aYaxis_position) +{ + // Text is NOT really mirrored; it is moved to a suitable position + // which is the closest position for a true mirrored text + // The center position is mirrored and the text is moved for half horizontal len + int px = m_Pos.x; + int dx; + if( m_Orient == 0 ) /* horizontal text */ + dx = LenSize( m_Text ) / 2; + else if( m_Orient == 2 ) /* invert horizontal text*/ + dx = -LenSize( m_Text ) / 2; + else + dx = 0; + px += dx; + px -= aYaxis_position; + NEGATE(px); + px += aYaxis_position; + px -= dx; + m_Pos.x = px; +} + /** function GetSchematicTextOffset (virtual) * @return the offset between the SCH_TEXT position and the text itself position * This offset depend on orientation, and the type of text @@ -221,6 +246,41 @@ wxPoint SCH_HIERLABEL::GetSchematicTextOffset() return text_offset; } +/** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ +void SCH_HIERLABEL::Mirror_Y(int aYaxis_position) +{ + // Text is NOT really mirrored; it is moved to a suitable position + // which is the closest position for a true mirrored text + // The center position is mirrored and the text is moved for half horizontal len + if( m_Orient == 0 ) /* horizontal text */ + m_Orient = 2; + else if( m_Orient == 2 ) /* invert horizontal text*/ + m_Orient = 0; + m_Pos.x -= aYaxis_position; + NEGATE(m_Pos.x); + m_Pos.x += aYaxis_position; +} + +/** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ +void SCH_GLOBALLABEL::Mirror_Y(int aYaxis_position) +{ + // Text is NOT really mirrored; it is moved to a suitable position + // which is the closest position for a true mirrored text + // The center position is mirrored and the text is moved for half horizontal len + if( m_Orient == 0 ) /* horizontal text */ + m_Orient = 2; + else if( m_Orient == 2 ) /* invert horizontal text*/ + m_Orient = 0; + m_Pos.x -= aYaxis_position; + NEGATE(m_Pos.x); + m_Pos.x += aYaxis_position; +} /** function GetSchematicTextOffset (virtual) * @return the offset between the SCH_TEXT position and the text itself position diff --git a/eeschema/class_text-label.h b/eeschema/class_text-label.h index 7a7da9ae38..a3bf02a1f5 100644 --- a/eeschema/class_text-label.h +++ b/eeschema/class_text-label.h @@ -102,6 +102,21 @@ public: */ int GetPenSize( ); + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) + { + m_Pos += aMoveVector; + } + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position); #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); @@ -209,6 +224,12 @@ public: * @param Pos = Position of the shape */ void CreateGraphicShape( std::vector & aCorner_list, const wxPoint& Pos ); + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position); }; @@ -268,6 +289,11 @@ public: bool HitTest( const wxPoint& aPosRef ); EDA_Rect GetBoundingBox(); + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position); }; #endif /* CLASS_TEXT_LABEL_H */ diff --git a/eeschema/eelibs_draw_components.cpp b/eeschema/eelibs_draw_components.cpp index 6302ee0b4b..41a69f1465 100644 --- a/eeschema/eelibs_draw_components.cpp +++ b/eeschema/eelibs_draw_components.cpp @@ -9,7 +9,6 @@ #include "drawtxt.h" #include "program.h" #include "libcmp.h" -#include "component_class.h" #include "general.h" #include "trigo.h" #include "protos.h" diff --git a/eeschema/geometric_transforms.cpp b/eeschema/geometric_transforms.cpp deleted file mode 100644 index b93518b922..0000000000 --- a/eeschema/geometric_transforms.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/****************************************************/ -/* BLOCK.CPP */ -/* Gestion des Operations sur Blocks et Effacements */ -/****************************************************/ - -#include "fctsys.h" -#include "appl_wxstruct.h" -#include "common.h" -#include "class_drawpanel.h" -#include "program.h" -#include "libcmp.h" -#include "general.h" -#include "class_marker_sch.h" - -#include "protos.h" - -/* Variables Locales */ - -/* Fonctions exportees */ -void MoveItemsInList( SCH_SCREEN* aScreen, PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); -void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint ); -void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& aMirrorPoint ); - - -/* -* Small function to mirror (relative to a vertiacl axis at aMirrorPoint.x position) -* a given point -*/ -static void MirrorYPoint( wxPoint& point, wxPoint& aMirrorPoint ) -{ - point.x -= aMirrorPoint.x; - NEGATE( point.x ); - point.x += aMirrorPoint.x; -} - - -/**************************************************************/ -void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& aMirrorPoint ) -/**************************************************************/ - -/* Given a structure rotate it to 90 degrees refer to the aMirrorPoint point. - */ -{ - int dx; - DrawPolylineStruct* DrawPoly; - DrawJunctionStruct* DrawConnect; - EDA_DrawLineStruct* DrawSegment; - DrawBusEntryStruct* DrawRaccord; - SCH_COMPONENT* DrawLibItem; - DrawSheetStruct* DrawSheet; - Hierarchical_PIN_Sheet_Struct* DrawSheetLabel; - MARKER_SCH* DrawMarker; - DrawNoConnectStruct* DrawNoConnect; - SCH_TEXT* DrawText; - wxPoint px; - - if( !DrawStruct ) - return; - - switch( DrawStruct->Type() ) - { - case TYPE_NOT_INIT: - break; - - case DRAW_POLYLINE_STRUCT_TYPE: - DrawPoly = (DrawPolylineStruct*) DrawStruct; - for( unsigned ii = 0; ii < DrawPoly->GetCornerCount(); ii++ ) - { - wxPoint point; - point = DrawPoly->m_PolyPoints[ii]; - MirrorYPoint( point, aMirrorPoint ); - DrawPoly->m_PolyPoints[ii] = point; - } - - break; - - case DRAW_SEGMENT_STRUCT_TYPE: - DrawSegment = (EDA_DrawLineStruct*) DrawStruct; - if( (DrawSegment->m_Flags & STARTPOINT) == 0 ) - { - MirrorYPoint( DrawSegment->m_Start, aMirrorPoint ); - } - if( (DrawSegment->m_Flags & ENDPOINT) == 0 ) - { - MirrorYPoint( DrawSegment->m_End, aMirrorPoint ); - } - break; - - case DRAW_BUSENTRY_STRUCT_TYPE: - DrawRaccord = (DrawBusEntryStruct*) DrawStruct; - MirrorYPoint( DrawRaccord->m_Pos, aMirrorPoint ); - NEGATE( DrawRaccord->m_Size.x ); - break; - - case DRAW_JUNCTION_STRUCT_TYPE: - DrawConnect = (DrawJunctionStruct*) DrawStruct; - MirrorYPoint( DrawConnect->m_Pos, aMirrorPoint ); - break; - - case DRAW_MARKER_STRUCT_TYPE: - DrawMarker = (MARKER_SCH*) DrawStruct; - MirrorYPoint( DrawMarker->m_Pos, aMirrorPoint ); - break; - - case DRAW_NOCONNECT_STRUCT_TYPE: - DrawNoConnect = (DrawNoConnectStruct*) DrawStruct; - MirrorYPoint( DrawNoConnect->m_Pos, aMirrorPoint ); - break; - - case TYPE_SCH_TEXT: - case TYPE_SCH_LABEL: - - // Text is NOT really mirrored; it is moved to a suitable position - // which is the closest position for a true mirrored text - // The center position is mirrored and the text is moved for half horizontal len - DrawText = (SCH_TEXT*) DrawStruct; - px = DrawText->m_Pos; - if( DrawText->m_Orient == 0 ) /* horizontal text */ - dx = DrawText->LenSize( DrawText->m_Text ) / 2; - else if( DrawText->m_Orient == 2 ) /* invert horizontal text*/ - dx = -DrawText->LenSize( DrawText->m_Text ) / 2; - else - dx = 0; - px.x += dx; - MirrorYPoint( px, aMirrorPoint ); - px.x -= dx; - DrawText->m_Pos.x = px.x; - break; - - case TYPE_SCH_HIERLABEL: - case TYPE_SCH_GLOBALLABEL: - - // Text is not really mirrored: Orientation is changed - DrawText = (SCH_LABEL*) DrawStruct; - if( DrawText->m_Orient == 0 ) /* horizontal text */ - DrawText->m_Orient = 2; - else if( DrawText->m_Orient == 2 ) /* invert horizontal text*/ - DrawText->m_Orient = 0; - - MirrorYPoint( DrawText->m_Pos, aMirrorPoint ); - break; - - case TYPE_SCH_COMPONENT: - { - DrawLibItem = (SCH_COMPONENT*) DrawStruct; - dx = DrawLibItem->m_Pos.x; - WinEDA_SchematicFrame* frame = (WinEDA_SchematicFrame*) wxGetApp().GetTopWindow(); - frame->CmpRotationMiroir( DrawLibItem, NULL, CMP_MIROIR_Y ); - MirrorYPoint( DrawLibItem->m_Pos, aMirrorPoint ); - dx -= DrawLibItem->m_Pos.x; // dx,0 is the move vector for this transform - - for( int ii = 0; ii < DrawLibItem->GetFieldCount(); ii++ ) - { - /* move the fields to the new position because the component itself has moved */ - DrawLibItem->GetField( ii )->m_Pos.x -= dx; - } - } - break; - - case DRAW_SHEET_STRUCT_TYPE: - DrawSheet = (DrawSheetStruct*) DrawStruct; - MirrorYPoint( DrawSheet->m_Pos, aMirrorPoint ); - DrawSheet->m_Pos.x -= DrawSheet->m_Size.x; - - DrawSheetLabel = DrawSheet->m_Label; - while( DrawSheetLabel != NULL ) - { - MirrorYPoint( DrawSheetLabel->m_Pos, aMirrorPoint ); - DrawSheetLabel->m_Edge = DrawSheetLabel->m_Edge ? 0 : 1; - DrawSheetLabel = - (Hierarchical_PIN_Sheet_Struct*) DrawSheetLabel->Next(); - } - - break; - - case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE: - DrawSheetLabel = (Hierarchical_PIN_Sheet_Struct*) DrawStruct; - MirrorYPoint( DrawSheetLabel->m_Pos, aMirrorPoint ); - break; - - default: - break; - } -} - - -/***************************************************************************** -* Routine to Mirror objects. * -*****************************************************************************/ -void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint ) -{ - for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) - { - SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetItemData( ii ); - MirrorOneStruct( item, aMirrorPoint ); // Place it in its new position. - item->m_Flags = 0; - } -} - - - -/***************************************************************************** -* Routine to place a given object. * -*****************************************************************************/ -void MoveItemsInList( SCH_SCREEN* aScreen, PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ) -{ - for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) - { - SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetItemData( ii ); - MoveOneStruct( item, aMoveVector ); - } -} - - -/**************************************************************************/ -void MoveOneStruct( SCH_ITEM* aItem, const wxPoint& aMoveVector ) -/*************************************************************************/ -/* Given a structure move it by aMoveVector. - */ -{ - DrawPolylineStruct* DrawPoly; - DrawJunctionStruct* DrawConnect; - EDA_DrawLineStruct* DrawSegment; - DrawBusEntryStruct* DrawRaccord; - SCH_COMPONENT* DrawLibItem; - DrawSheetStruct* DrawSheet; - Hierarchical_PIN_Sheet_Struct* DrawSheetLabel; - MARKER_SCH* DrawMarker; - DrawNoConnectStruct* DrawNoConnect; - - if( !aItem ) - return; - - switch( aItem->Type() ) - { - case TYPE_NOT_INIT: - break; - - case DRAW_POLYLINE_STRUCT_TYPE: - DrawPoly = (DrawPolylineStruct*) aItem; - for( unsigned ii = 0; ii < DrawPoly->GetCornerCount(); ii++ ) - { - DrawPoly->m_PolyPoints[ii] += aMoveVector; - } - - break; - - case DRAW_SEGMENT_STRUCT_TYPE: - DrawSegment = (EDA_DrawLineStruct*) aItem; - if( (DrawSegment->m_Flags & STARTPOINT) == 0 ) - { - DrawSegment->m_Start += aMoveVector; - } - if( (DrawSegment->m_Flags & ENDPOINT) == 0 ) - { - DrawSegment->m_End += aMoveVector; - } - break; - - case DRAW_BUSENTRY_STRUCT_TYPE: - DrawRaccord = (DrawBusEntryStruct*) aItem; - DrawRaccord->m_Pos += aMoveVector; - break; - - case DRAW_JUNCTION_STRUCT_TYPE: - DrawConnect = (DrawJunctionStruct*) aItem; - DrawConnect->m_Pos += aMoveVector; - break; - - case DRAW_MARKER_STRUCT_TYPE: - DrawMarker = (MARKER_SCH*) aItem; - DrawMarker->m_Pos += aMoveVector; - break; - - case DRAW_NOCONNECT_STRUCT_TYPE: - DrawNoConnect = (DrawNoConnectStruct*) aItem; - DrawNoConnect->m_Pos += aMoveVector; - break; - - case TYPE_SCH_TEXT: - #define DrawText ( (SCH_TEXT*) aItem ) - DrawText->m_Pos += aMoveVector; - break; - - case TYPE_SCH_LABEL: - #define DrawLabel ( (SCH_LABEL*) aItem ) - DrawLabel->m_Pos += aMoveVector; - break; - - case TYPE_SCH_HIERLABEL: - case TYPE_SCH_GLOBALLABEL: - #define DrawGHLabel ( (SCH_LABEL*) aItem ) - DrawGHLabel->m_Pos += aMoveVector; - break; - - case TYPE_SCH_COMPONENT: - DrawLibItem = (SCH_COMPONENT*) aItem; - DrawLibItem->m_Pos += aMoveVector; - for( int ii = 0; ii < DrawLibItem->GetFieldCount(); ii++ ) - { - DrawLibItem->GetField( ii )->m_Pos += aMoveVector; - } - - break; - - case DRAW_SHEET_STRUCT_TYPE: - DrawSheet = (DrawSheetStruct*) aItem; - DrawSheet->m_Pos += aMoveVector; - DrawSheetLabel = DrawSheet->m_Label; - while( DrawSheetLabel != NULL ) - { - DrawSheetLabel->m_Pos += aMoveVector; - DrawSheetLabel = DrawSheetLabel->Next(); - } - - break; - - case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE: - DrawSheetLabel = (Hierarchical_PIN_Sheet_Struct*) aItem; - DrawSheetLabel->m_Pos += aMoveVector; - break; - - default: - break; - } -} diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 51cbdc0548..228c21bd55 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -258,9 +258,8 @@ static void ShowWhileMoving( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) DrawStructsInGhost( panel, DC, Component, wxPoint(0,0) ); } - move_vector.x = screen->m_Curseur.x - Component->m_Pos.x; - move_vector.y = screen->m_Curseur.y - Component->m_Pos.y; - MoveOneStruct( Component, move_vector ); + move_vector = screen->m_Curseur - Component->m_Pos; + Component->Move( move_vector ); DrawStructsInGhost( panel, DC, Component, wxPoint(0,0) ); } @@ -327,15 +326,9 @@ static void ExitPlaceCmp( WinEDA_DrawPanel* Panel, wxDC* DC ) } else if( Component ) /* Deplacement ancien composant en cours */ { - wxPoint move_vector; - - move_vector.x = OldPos.x - Component->m_Pos.x; - move_vector.y = OldPos.y - Component->m_Pos.y; - - MoveOneStruct( Component, move_vector ); - + wxPoint move_vector = OldPos - Component->m_Pos; + Component->Move( move_vector ); memcpy( Component->m_Transform, OldTransMat, sizeof(OldTransMat) ); - Component->m_Flags = 0; } diff --git a/eeschema/operations_on_items_lists.cpp b/eeschema/operations_on_items_lists.cpp new file mode 100644 index 0000000000..7651114834 --- /dev/null +++ b/eeschema/operations_on_items_lists.cpp @@ -0,0 +1,281 @@ +/*************************************************** + * operations_on_item_lists.cpp + * functions used in block commands, on lists of schematic items: + * move, mirror, delete anc copy + ****************************************************/ + +#include "fctsys.h" +#include "appl_wxstruct.h" +#include "common.h" +#include "class_drawpanel.h" +#include "program.h" +#include "libcmp.h" +#include "general.h" +#include "class_marker_sch.h" + +#include "protos.h" + +/* Exported Functions */ +void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); +void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint ); +void DeleteItemsInList( WinEDA_DrawPanel* panel, PICKED_ITEMS_LIST& aItemsList ); +void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ); + + +/***************************************************************************** +* Routine to Mirror objects. * +*****************************************************************************/ +void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint ) +{ + for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) + { + SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetItemData( ii ); + item->Mirror_Y( aMirrorPoint.x ); // Place it in its new position. + item->m_Flags = 0; + } +} + + + +/** Function MoveItemsInList +* Move a list of items to a givent move vector +* @param aItemsList = list of picked items +* @param aMoveVector = the move vector value +*/ +void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ) +{ + for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) + { + SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetItemData( ii ); + item->Move( aMoveVector ); + } +} + + + +/** function DeleteItemsInList + * delete schematic items in aItemsList + * deleted items are put in undo list + */ +void DeleteItemsInList( WinEDA_DrawPanel* panel, PICKED_ITEMS_LIST& aItemsList ) +{ + SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen(); + WinEDA_SchematicFrame* frame = (WinEDA_SchematicFrame*) panel->m_Parent; + PICKED_ITEMS_LIST itemsList; + ITEM_PICKER itemWrapper; + + for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) + { + SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetItemData( ii ); + itemWrapper.m_Item = item; + itemWrapper.m_UndoRedoStatus = UR_DELETED; + if( item->Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) + { + /* this item is depending on a sheet, and is not in global list */ + wxMessageBox( wxT( + "DeleteItemsInList() err: unexpected DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE" ) ); +#if 0 + Hierarchical_PIN_Sheet_Struct* pinlabel = (Hierarchical_PIN_Sheet_Struct*) item; + frame->DeleteSheetLabel( false, pinlabel->m_Parent ); + itemWrapper.m_Item = pinlabel->m_Parent; + itemWrapper.m_UndoRedoStatus = UR_CHANGED; + itemsList.PushItem( itemWrapper ); +#endif + } + else + { + screen->RemoveFromDrawList( item ); + + /* Unlink the structure */ + item->SetNext( 0 ); + item->SetBack( 0 ); + itemsList.PushItem( itemWrapper ); + } + } + + frame->SaveCopyInUndoList( itemsList, UR_DELETED ); +} + + +/*********************************************************************************/ +void DeleteStruct( WinEDA_DrawPanel* panel, wxDC* DC, SCH_ITEM* DrawStruct ) +/*********************************************************************************/ + +/* Routine to delete an object from global drawing object list. + * Object is put in Undo list + */ +{ + SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen(); + WinEDA_SchematicFrame* frame = (WinEDA_SchematicFrame*) panel->m_Parent; + + if( !DrawStruct ) + return; + + if( DrawStruct->Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) + { + /* Cette stucture est rattachee a une feuille, et n'est pas + * accessible par la liste globale directement */ + frame->SaveCopyInUndoList( (SCH_ITEM*)( (Hierarchical_PIN_Sheet_Struct + *) DrawStruct )->GetParent(), + UR_CHANGED ); + frame->DeleteSheetLabel( DC ? true : false, + (Hierarchical_PIN_Sheet_Struct*) DrawStruct ); + return; + } + + else /* structure classique */ + { + screen->RemoveFromDrawList( DrawStruct ); + + panel->PostDirtyRect( DrawStruct->GetBoundingBox() ); + + /* Unlink the structure */ + DrawStruct->SetNext( 0 ); + DrawStruct->SetBack( 0 ); // Only one struct -> no link + + frame->SaveCopyInUndoList( DrawStruct, UR_DELETED ); + } +} + + + +/*****************************************************************************/ +void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector ) +/*****************************************************************************/ + +/* Routine to copy a new entity of an object for each object in list and reposition it. + * Return the new created object list in aItemsList + */ +{ + SCH_ITEM* newitem; + + if( aItemsList.GetCount() == 0 ) + return; + + for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) + { + newitem = DuplicateStruct( (SCH_ITEM*) aItemsList.GetItemData( ii ) ); + aItemsList.SetItem( newitem, ii ); + aItemsList.SetItemStatus( UR_NEW, ii ); + { + switch( newitem->Type() ) + { + case DRAW_POLYLINE_STRUCT_TYPE: + case DRAW_JUNCTION_STRUCT_TYPE: + case DRAW_SEGMENT_STRUCT_TYPE: + case DRAW_BUSENTRY_STRUCT_TYPE: + case TYPE_SCH_TEXT: + case TYPE_SCH_LABEL: + case TYPE_SCH_GLOBALLABEL: + case TYPE_SCH_HIERLABEL: + case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE: + case DRAW_MARKER_STRUCT_TYPE: + case DRAW_NOCONNECT_STRUCT_TYPE: + default: + break; + + case DRAW_SHEET_STRUCT_TYPE: + { + DrawSheetStruct* sheet = (DrawSheetStruct*) newitem; + sheet->m_TimeStamp = GetTimeStamp(); + sheet->SetSon( NULL ); + break; + } + + case TYPE_SCH_COMPONENT: + ( (SCH_COMPONENT*) newitem )->m_TimeStamp = GetTimeStamp(); + ( (SCH_COMPONENT*) newitem )->ClearAnnotation( NULL ); + break; + } + + SetaParent( newitem, screen ); + newitem->SetNext( screen->EEDrawList ); + screen->EEDrawList = newitem; + } + } + + MoveItemsInList( aItemsList, aMoveVector ); +} + + +/************************************************************/ +SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct ) +/************************************************************/ + +/* Routine to create a new copy of given struct. + * The new object is not put in draw list (not linked) + */ +{ + SCH_ITEM* NewDrawStruct = NULL; + + if( DrawStruct == NULL ) + { + wxMessageBox( wxT( "DuplicateStruct error: NULL struct" ) ); + return NULL; + } + + switch( DrawStruct->Type() ) + { + case DRAW_POLYLINE_STRUCT_TYPE: + NewDrawStruct = ( (DrawPolylineStruct*) DrawStruct )->GenCopy(); + break; + + case DRAW_SEGMENT_STRUCT_TYPE: + NewDrawStruct = ( (EDA_DrawLineStruct*) DrawStruct )->GenCopy(); + break; + + case DRAW_BUSENTRY_STRUCT_TYPE: + NewDrawStruct = ( (DrawBusEntryStruct*) DrawStruct )->GenCopy(); + break; + + case DRAW_JUNCTION_STRUCT_TYPE: + NewDrawStruct = ( (DrawJunctionStruct*) DrawStruct )->GenCopy(); + break; + + case DRAW_MARKER_STRUCT_TYPE: + NewDrawStruct = ( (MARKER_SCH*) DrawStruct )->GenCopy(); + break; + + case DRAW_NOCONNECT_STRUCT_TYPE: + NewDrawStruct = ( (DrawNoConnectStruct*) DrawStruct )->GenCopy(); + break; + + case TYPE_SCH_TEXT: + NewDrawStruct = ( (SCH_TEXT*) DrawStruct )->GenCopy(); + break; + + case TYPE_SCH_LABEL: + NewDrawStruct = ( (SCH_LABEL*) DrawStruct )->GenCopy(); + break; + + case TYPE_SCH_HIERLABEL: + NewDrawStruct = ( (SCH_HIERLABEL*) DrawStruct )->GenCopy(); + break; + + case TYPE_SCH_GLOBALLABEL: + NewDrawStruct = ( (SCH_GLOBALLABEL*) DrawStruct )->GenCopy(); + break; + + case TYPE_SCH_COMPONENT: + NewDrawStruct = ( (SCH_COMPONENT*) DrawStruct )->GenCopy(); + break; + + case DRAW_SHEET_STRUCT_TYPE: + NewDrawStruct = ( (DrawSheetStruct*) DrawStruct )->GenCopy(); + break; + + default: + { + wxString msg; + msg << wxT( "DuplicateStruct error: unexpected StructType " ) << + DrawStruct->Type() << wxT( " " ) << DrawStruct->GetClass(); + wxMessageBox( msg ); + } + break; + } + + NewDrawStruct->m_Image = DrawStruct; + return NewDrawStruct; +} + + diff --git a/eeschema/program.h b/eeschema/program.h index 6373d94e45..d2f51afd07 100644 --- a/eeschema/program.h +++ b/eeschema/program.h @@ -10,7 +10,7 @@ #include "base_struct.h" #include "sch_item_struct.h" -#include "component_class.h" +#include "class_sch_component.h" #include "class_sch_screen.h" #include "class_drawsheet.h" #include "class_drawsheetpath.h" diff --git a/eeschema/protos.h b/eeschema/protos.h index 76daea39b1..181543888c 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -93,9 +93,6 @@ char * StrPurge(char * text); /* BLOCK.CPP */ /************/ SCH_ITEM * DuplicateStruct(SCH_ITEM *DrawStruct); -void MoveOneStruct(SCH_ITEM *DrawStructs, const wxPoint & move_vector); - /* Given a structure move it by move_vector. */ - void DeleteStruct(WinEDA_DrawPanel * panel, wxDC * DC, SCH_ITEM *DrawStruct); /*************/ diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index 8e1317e0d7..ce6a92b82f 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -13,9 +13,6 @@ #include "class_marker_sch.h" -// Imported functions -void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& aMirrorPoint ); - /* Functions to undo and redo edit commands. * commmands to undo are stored in CurrentScreen->m_UndoList * commmands to redo are stored in CurrentScreen->m_RedoList @@ -344,6 +341,7 @@ void WinEDA_SchematicFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList ) { SCH_ITEM* item; SCH_ITEM* alt_item; + bool as_moved = false; for( unsigned ii = 0; ii < aList->GetCount(); ii++ ) { @@ -371,17 +369,14 @@ void WinEDA_SchematicFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList ) break; case UR_MOVED: - { - wxPoint moveVector = - aList->m_TransformPoint; - MoveOneStruct( item, moveVector ); - aList->m_TransformPoint = moveVector; - } + item->Move( - aList->m_TransformPoint ); + as_moved = true; break; case UR_MIRRORED_Y: { wxPoint mirrorPoint = aList->m_TransformPoint; - MirrorOneStruct( item, mirrorPoint ); + item->Mirror_Y( mirrorPoint.x ); } break; @@ -411,6 +406,10 @@ void WinEDA_SchematicFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList ) break; } } + + // Undo for move transform needs to change the general move vector: + if ( as_moved ) + aList->m_TransformPoint = - aList->m_TransformPoint; } diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 4f1b0ed260..d4ffa8c5c6 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -485,9 +485,8 @@ static void DeplaceSheet( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) } else /* Move Sheet */ { - move_vector.x = screen->m_Curseur.x - Sheet->m_Pos.x; - move_vector.y = screen->m_Curseur.y - Sheet->m_Pos.y; - MoveOneStruct( Sheet, move_vector ); + move_vector = screen->m_Curseur - Sheet->m_Pos; + Sheet->Move( move_vector ); } RedrawOneStruct( panel, DC, Sheet, g_XorMode ); diff --git a/include/sch_item_struct.h b/include/sch_item_struct.h index a778f7b36b..9ab62bcd19 100644 --- a/include/sch_item_struct.h +++ b/include/sch_item_struct.h @@ -62,9 +62,22 @@ public: int Color = -1 ) = 0; - /* fonction de placement */ + /* Place function */ virtual void Place( WinEDA_SchematicFrame* frame, wxDC* DC ); + // Geometric transforms (used in block operations): + /** virtual function Move + * move item to a new position. + * @param aMoveVector = the deplacement vector + */ + virtual void Move(const wxPoint& aMoveVector) = 0; + + /** virtual function Mirror_Y + * mirror item relative to an Y axis + * @param aYaxis_position = the y axis position + */ + virtual void Mirror_Y(int aYaxis_position) = 0; + /** * Function Save * writes the data structures for this object out to a FILE in "*.sch" diff --git a/pcbnew/dialog_print_using_printer.cpp b/pcbnew/dialog_print_using_printer.cpp index b0d1cf093b..60c403a146 100644 --- a/pcbnew/dialog_print_using_printer.cpp +++ b/pcbnew/dialog_print_using_printer.cpp @@ -238,9 +238,9 @@ void DIALOG_PRINT_USING_PRINTER::OnInitDialog( wxInitDialogEvent& event ) // Create scale adjust option - msg.Printf( wxT( "%lf" ), m_XScaleAdjust ); + msg.Printf( wxT( "%f" ), m_XScaleAdjust ); m_FineAdjustXscaleOpt->SetValue( msg ); - msg.Printf( wxT( "%lf" ), m_YScaleAdjust ); + msg.Printf( wxT( "%f" ), m_YScaleAdjust ); m_FineAdjustYscaleOpt->SetValue( msg ); if( GetSizer() )