← Back to team overview

kicad-developers team mailing list archive

Re: [FEATURE] Add keepout areas in footprints

 

Le 19/10/2017 à 17:26, Maciej Sumiński a écrit :
> On 10/19/2017 05:20 PM, jp charras wrote:
>> Le 19/10/2017 à 16:59, Maciej Sumiński a écrit :
>>> On 10/19/2017 04:32 PM, jp charras wrote:
>>> [snip]
>>>> Hi Orson,
>>>>
>>>> Could you have a look into this patch?
>>>> It fixes the issue when a change is committed with a item belonging a footprint.
>>>>
>>>> But I do not have very good knowledge of COMMIT classes.
>>>
>>> Hi Jean-Pierre,
>>>
>>> Thank you for looking into the problem. In the proposed patch
>>> BOARD_COMMIT will try to save the item parent even for items that do not
>>> belong to modules (e.g. tracks, vias), ending up with the whole board
>>> stored in the undo buffer.
>>
>> In fact no: the parent is used only if it is a MODULE (due to the dynamic_cast)
> 
> You are right, I realized it a bit too late.
> 
>> However the patch can save many times the same MODULE, in
>> COMMIT& BOARD_COMMIT::Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType )
>> if the container contains many items of the same MODULE (perhaps no a major issue, but...).
> 
> It should not be a problem, there is a countermeasure for such case in
> COMMIT::createModified(), which normally is invoked by COMMIT::Stage().
> 
>> The patch is not really finished, in fact.
> 
> Now I see it is quite possible the patch might be complete. The only
> thing I would suggest is to change dynamic_cast to checking
> EDA_ITEM::Type() return value.
> 

OK.
This patch should work better, but need more tests.

@Oliver
Could you test this patch and fix other pending issues about keepout in footprints

Thanks.


-- 
Jean-Pierre CHARRAS
 include/commit.h        |  6 +++---
 pcbnew/board_commit.cpp | 29 ++++++++++++++++++++++++++++-
 pcbnew/board_commit.h   |  6 +++++-
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/include/commit.h b/include/commit.h
index d883bba..f2a436a 100644
--- a/include/commit.h
+++ b/include/commit.h
@@ -123,11 +123,11 @@ public:
 
 
     ///> Adds a change of the item aItem of type aChangeType to the change list.
-    COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType );
+    virtual COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType );
 
-    COMMIT& Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType );
+    virtual COMMIT& Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType );
 
-    COMMIT& Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag = UR_UNSPECIFIED );
+    virtual COMMIT& Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag = UR_UNSPECIFIED );
 
     ///> Executes the changes.
     virtual void Push( const wxString& aMessage = wxT( "A commit" ), bool aCreateUndoEntry = true ) = 0;
diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp
index df2a192..0f40ae9 100644
--- a/pcbnew/board_commit.cpp
+++ b/pcbnew/board_commit.cpp
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2016 CERN
+ * Copyright (C) 2017 CERN
  * @author Tomasz Wlostowski <tomasz.wlostowski@xxxxxxx>
  *
  * This program is free software; you can redistribute it and/or
@@ -56,6 +56,33 @@ BOARD_COMMIT::~BOARD_COMMIT()
 }
 
 
+COMMIT& BOARD_COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType )
+{
+    // if aItem belongs a footprint, the full footprint will be saved
+    // because undo/redo does not handle "sub items" modifications
+    if( aItem && aItem->Type() != PCB_MODULE_T && aChangeType == CHT_MODIFY)
+    {
+        EDA_ITEM* item = aItem->GetParent();
+
+        if( item && item->Type() == PCB_MODULE_T )  // means aItem belongs a footprint
+            aItem = item;
+    }
+
+    return COMMIT::Stage( aItem, aChangeType );
+}
+
+
+COMMIT& BOARD_COMMIT::Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType )
+{
+    return COMMIT::Stage( container, aChangeType );
+}
+
+COMMIT& BOARD_COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag )
+{
+    return COMMIT::Stage( aItems, aModFlag );
+}
+
+
 void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry )
 {
     // Objects potentially interested in changes:
diff --git a/pcbnew/board_commit.h b/pcbnew/board_commit.h
index 197bbfb..8164e9c 100644
--- a/pcbnew/board_commit.h
+++ b/pcbnew/board_commit.h
@@ -1,7 +1,7 @@
 /*
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
- * Copyright (C) 2016 CERN
+ * Copyright (C) 2017 CERN
  * @author Tomasz Wlostowski <tomasz.wlostowski@xxxxxxx>
  *
  * This program is free software; you can redistribute it and/or
@@ -43,6 +43,10 @@ public:
     virtual void Push( const wxString& aMessage = wxT( "A commit" ), bool aCreateUndoEntry = true ) override;
     virtual void Revert() override;
 
+    virtual COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) override;
+    virtual COMMIT& Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType ) override;
+    virtual COMMIT& Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag = UR_UNSPECIFIED ) override;
+
 private:
     TOOL_MANAGER* m_toolMgr;
     bool m_editModules;

Follow ups

References