[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: Ground color



Hi Ben,

While testing the patch (attached) I made against my LockElements(All|
Selected) /UnlockElements(All|Selected) plugin (attached) I came to the
conclusion that the behaviour now is equal whether "All" or "Selected"
is used as an argument.

Both arguments lock/unlock all elements.

Not exactly what I had in mind.

I will gives this another try tomorrow night :)

Kind regards,

Bert Timmerman.


--- src/select.orig	2008-05-19 16:52:31.000000000 +0200
+++ src/select.c	2008-06-23 23:20:25.000000000 +0200
@@ -264,7 +264,7 @@
   return (changed);
 }
 
-/* ----------------------------------------------------------------------
+/*! ----------------------------------------------------------------------
  * selects/unselects all visible objects within the passed box
  * Flag determines if the block is to be selected or unselected
  * returns True if the state of any object has changed
@@ -277,8 +277,9 @@
   if (PCB->RatOn || !Flag)
     RAT_LOOP (PCB->Data);
   {
-    if (LINE_IN_BOX ((LineTypePtr) line, Box) &&
-	!TEST_FLAG (LOCKFLAG, line) && TEST_FLAG (SELECTEDFLAG, line) != Flag)
+    if (LINE_IN_BOX ((LineTypePtr) line, Box) 
+        && (!TEST_FLAG (LOCKFLAG, line) || !Flag)
+        && TEST_FLAG (SELECTEDFLAG, line) != Flag)
       {
 	AddObjectToFlagUndoList (RATLINE_TYPE, line, line, line);
 	ASSIGN_FLAG (SELECTEDFLAG, Flag, line);
@@ -298,7 +299,7 @@
     LINE_LOOP (layer);
     {
       if (LINE_IN_BOX (line, Box)
-	  && !TEST_FLAG (LOCKFLAG, line)
+	  && (!TEST_FLAG (LOCKFLAG, line) || !Flag)
 	  && TEST_FLAG (SELECTEDFLAG, line) != Flag)
 	{
 	  AddObjectToFlagUndoList (LINE_TYPE, layer, line, line);
@@ -312,7 +313,7 @@
     ARC_LOOP (layer);
     {
       if (ARC_IN_BOX (arc, Box)
-	  && !TEST_FLAG (LOCKFLAG, arc)
+	  && (!TEST_FLAG (LOCKFLAG, arc) || !Flag)
 	  && TEST_FLAG (SELECTEDFLAG, arc) != Flag)
 	{
 	  AddObjectToFlagUndoList (ARC_TYPE, layer, arc, arc);
@@ -328,7 +329,7 @@
       if (!Flag || TEXT_IS_VISIBLE(PCB, layer, text))
 	{
 	  if (TEXT_IN_BOX (text, Box)
-	      && !TEST_FLAG (LOCKFLAG, text)
+	      && (!TEST_FLAG (LOCKFLAG, text) || !Flag)
 	      && TEST_FLAG (SELECTEDFLAG, text) != Flag)
 	    {
 	      AddObjectToFlagUndoList (TEXT_TYPE, layer, text, text);
@@ -343,7 +344,7 @@
     POLYGON_LOOP (layer);
     {
       if (POLYGON_IN_BOX (polygon, Box)
-	  && !TEST_FLAG (LOCKFLAG, polygon)
+	  && (!TEST_FLAG (LOCKFLAG, polygon) || !Flag)
 	  && TEST_FLAG (SELECTEDFLAG, polygon) != Flag)
 	{
 	  AddObjectToFlagUndoList (POLYGON_TYPE, layer, polygon, polygon);
@@ -363,13 +364,13 @@
     {
       Boolean gotElement = False;
       if ((PCB->ElementOn || !Flag)
-	  && !TEST_FLAG (LOCKFLAG, element)
+	  && (!TEST_FLAG (LOCKFLAG, element) || !Flag)
 	  && ((TEST_FLAG (ONSOLDERFLAG, element) != 0) == SWAP_IDENT
 	      || PCB->InvisibleObjectsOn))
 	{
 	  if (BOX_IN_BOX
 	      (&ELEMENT_TEXT (PCB, element).BoundingBox, Box)
-	      && !TEST_FLAG (LOCKFLAG, &ELEMENT_TEXT (PCB, element))
+	      && (!TEST_FLAG (LOCKFLAG, &ELEMENT_TEXT (PCB, element)) || !Flag)
 	      && TEST_FLAG (SELECTEDFLAG,
 			    &ELEMENT_TEXT (PCB, element)) != Flag)
 	    {
@@ -421,7 +422,9 @@
 		gotElement = True;
 	      }
 	}
-      if ((PCB->PinOn || !Flag) && !TEST_FLAG (LOCKFLAG, element) && !gotElement)
+      if ((PCB->PinOn || !Flag) 
+          && (!TEST_FLAG (LOCKFLAG, element) || !Flag)
+          && !gotElement)
 	{
 	  PIN_LOOP (element);
 	  {
@@ -458,7 +461,7 @@
     VIA_LOOP (PCB->Data);
   {
     if (VIA_OR_PIN_IN_BOX (via, Box)
-	&& !TEST_FLAG (LOCKFLAG, via)
+	&& (!TEST_FLAG (LOCKFLAG, via) || !Flag)
 	&& TEST_FLAG (SELECTEDFLAG, via) != Flag)
       {
 	AddObjectToFlagUndoList (VIA_TYPE, via, via, via);
/*!
 * \file lockelements.c
 * \author Copyright (C) 2008 by Bert Timmerman <bert.timmerman@xxxxxxxxx>
 * \brief Unlocking/locking elements plug-in for PCB.
 *
 * Function to lock/unlock all/selected PCB elements.
 * \n
 * Compile like this:\n
 * \n
 * gcc -Ipath/to/pcb/src -Ipath/to/pcb -O2 -shared lockelements.c -o lockelements.so
 * \n\n
 * The resulting lockelements.so file should go in $HOME/.pcb/plugins/\n
 * \n
 * \warning Be very strict in compiling this plug-in against the exact pcb
 * sources you compiled/installed the pcb executable (i.e. src/pcb) with.\n
 * \n
 * Usage: LockElements([Selected|All])\n
 * Usage: UnlockElements([Selected|All])\n
 * \n
 * If no argument is passed, no locking/unlocking of elements is carried out.\n
 * \n
 * \bug When locking a selection of elements, it is not easy to unselect the
 * selection since those elements and their pins/pads/elementlines/elementarcs
 * are now locked ;)\n
 * This appears to be a bug in pcb.\n
 * \todo A possible workaround would be to clear the selected flag of the
 * locked element at the same instance the lock flag was set.
 * <hr>
 * This program is free software; you can redistribute it and/or modify\n
 * it under the terms of the GNU General Public License as published by\n
 * the Free Software Foundation; either version 2 of the License, or\n
 * (at your option) any later version.\n
 * \n
 * This program is distributed in the hope that it will be useful,\n
 * but WITHOUT ANY WARRANTY; without even the implied warranty of\n
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.\n
 * \n
 * You should have received a copy of the GNU General Public License\n
 * along with this program; if not, write to:\n
 * the Free Software Foundation, Inc.,\n
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n
 */


#include <stdio.h>
#include <math.h>

#include "global.h"
#include "data.h"
#include "hid.h"
#include "misc.h"
#include "create.h"
#include "rtree.h"
#include "undo.h"
#include "set.h"

/*!
 * \brief Locking all or selected elements.
 *
 * Usage: LockElements([Selected|All])\n
 * If no argument is passed, no action is carried out.
 */
static int
lock_elements(int argc, char **argv)
{
        int selected;
        int all;
        if (argc > 0 && strcasecmp (argv[0], "Selected") == 0)
                selected = 1;
        else if (argc >0 && strcasecmp (argv[0], "All") == 0)
                all = 1;
        else
        {
                Message ("ERROR: in LockElements argument should be either Selected or All.\n");
                return 1;
        }
        SET_FLAG (NAMEONPCBFLAG, PCB);
        ELEMENT_LOOP(PCB->Data);
        {
                if (!TEST_FLAG (LOCKFLAG, element))
                {
                        /* element is not locked */
                        if (all)
                                SET_FLAG(LOCKFLAG, element);
                        if (selected)
                        {
                                if (TEST_FLAG (SELECTEDFLAG, element))
                                {
                                        /* better to unselect element first */
                                        CLEAR_FLAG(SELECTEDFLAG, element);
                                        SET_FLAG(LOCKFLAG, element);
                                }
                        }
                }
        }
        END_LOOP;
        gui->invalidate_all ();
        IncrementUndoSerialNumber ();
        return 0;
}


/*!
 * \brief Locking all or selected elements.
 *
 * Usage: UnlockElements([Selected|All])\n
 * If no argument is passed, no action is carried out.
 */
static int
unlock_elements(int argc, char **argv)
{
        int selected;
        int all;
        if (argc > 0 && strcasecmp (argv[0], "Selected") == 0)
                selected = 1;
        else if (strcasecmp (argv[0], "All") == 0)
                all = 1;
        else
        {
                Message ("ERROR: in UnlockElements argument should be either Selected or All.\n");
                return 1;
        }
        SET_FLAG (NAMEONPCBFLAG, PCB);
        ELEMENT_LOOP(PCB->Data);
        {
                if (TEST_FLAG (LOCKFLAG, element))
                {
                        /* element is locked */
                        if (all)
                                CLEAR_FLAG(LOCKFLAG, element);
                        if (selected)
                        {
                                if (TEST_FLAG (SELECTEDFLAG, element))
                                        CLEAR_FLAG(LOCKFLAG, element);
                        }
                }
        }
        END_LOOP;
        gui->invalidate_all ();
        IncrementUndoSerialNumber ();
        return 0;
}


static HID_Action lockelements_action_list[] =
{
        {"LockElements", NULL, lock_elements, "Lock selected or all elements", NULL},
        {"UnlockElements", NULL, unlock_elements, "Unlock selected or all elements", NULL}
};


REGISTER_ACTIONS (lockelements_action_list)


void
pcb_plugin_init()
{
        register_lockelements_action_list();
}

/* EOF */

_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user