diff --git a/commands/CmdFI.c b/commands/CmdFI.c index 76eb269f..cfd4066b 100644 --- a/commands/CmdFI.c +++ b/commands/CmdFI.c @@ -2050,7 +2050,7 @@ CmdFlatten(w, cmd) } use = (CellUse *)HashGetValue(he); UndoDisable(); - DBFlattenInPlace(use, EditCellUse, xMask, dolabels, toplabels); + DBFlattenInPlace(use, EditCellUse, xMask, dolabels, toplabels, TRUE); UndoEnable(); } else @@ -2062,8 +2062,12 @@ CmdFlatten(w, cmd) scx.scx_trans = SelectUse->cu_transform; DBCellFlattenAllCells(&scx, EditCellUse, xMask, dolabels, toplabels); + + /* Instances in SelectDef need to be removed. The 2nd */ + /* argument TRUE causes the selection to be deleted. */ + SelectDeleteUses("flattened", TRUE); + UndoEnable(); - SelectClear(); } return; } diff --git a/database/DBcellcopy.c b/database/DBcellcopy.c index 7c7ce945..ebfd15dd 100644 --- a/database/DBcellcopy.c +++ b/database/DBcellcopy.c @@ -553,12 +553,13 @@ DBFlatCopyMaskHints(scx, xMask, targetUse) */ void -DBFlattenInPlace(use, dest, xMask, dolabels, toplabels) +DBFlattenInPlace(use, dest, xMask, dolabels, toplabels, doclear) CellUse *use; /* Cell use to flatten */ CellUse *dest; /* Cell use to flatten into */ int xMask; /* Search mask for flattening */ bool dolabels; /* Option to flatten labels */ bool toplabels; /* Option to selectively flatten top-level labels */ + bool doclear; /* Delete the original use if TRUE */ { Label *lab; SearchContext scx; @@ -678,7 +679,8 @@ DBFlattenInPlace(use, dest, xMask, dolabels, toplabels) lab->lab_flags &= ~LABEL_GENERATE; /* Remove the use from the parent def */ - DBDeleteCell(scx.scx_use); + if (doclear) + DBDeleteCell(scx.scx_use); /* Was: &scx.scx_use->cu_def->cd_bbox */ DBWAreaChanged(dest->cu_def, &scx.scx_use->cu_bbox, @@ -730,7 +732,7 @@ dbCellFlattenCellsFunc(scx, clientData) toplabels = fad->fad_toplabels; use = scx->scx_use; - DBFlattenInPlace(use, dest, xMask, dolabels, toplabels); + DBFlattenInPlace(use, dest, xMask, dolabels, toplabels, FALSE); return 2; } diff --git a/select/selOps.c b/select/selOps.c index f0fedea0..3305b48f 100644 --- a/select/selOps.c +++ b/select/selOps.c @@ -145,6 +145,64 @@ SelectDelete(msg, do_clear) if (do_clear) SelectClear(); } +/* + * ---------------------------------------------------------------------------- + * + * SelectDeleteUses -- + * + * Delete all cell uses in the edit cell that are selected. + * This function is used by "flatten -doinplace" when operating + * on a selection. Since selected instances are flattened, the + * instances need to be deleted from the cell. This routine is + * the same as SelectDelete() without the paint and label delete + * functions. + * + * Results: + * None. + * + * Side effects: + * Cell uses are removed from the edit cell. If there are selected + * uses that aren't in the edit cell, the user is warned. + * + * ---------------------------------------------------------------------------- + */ + +void +SelectDeleteUses(msg, do_clear) + char *msg; /* Some information to print in error messages. + * For example, if called as part of a move procedure, + * supply "moved". This will appear in messages of + * the form "only edit cell information was moved". + */ + bool do_clear; /* If TRUE, clear the select def before returning. */ +{ + bool nonEdit; + Rect editArea; + + extern int selDelPaintFunc(), selDelCellFunc(), selDelLabelFunc(); + + if (EditCellUse == NULL) + { + TxError("The current cell is not editable.\n"); + return; + } + (void) SelEnumCells(TRUE, &nonEdit, (SearchContext *) NULL, + selDelCellFunc, (ClientData) NULL); + if (nonEdit) + { + TxError("You selected one or more subcells that aren't children\n"); + TxError(" of the edit cell. Only those in the edit cell were\n"); + TxError(" %s.\n", msg); + } + + DBReComputeBbox(EditCellUse->cu_def); + GeoTransRect(&RootToEditTransform, &SelectDef->cd_extended, &editArea); + DBWAreaChanged(EditCellUse->cu_def, &editArea, DBW_ALLWINDOWS, + (TileTypeBitMask *) NULL); + DRCCheckThis(EditCellUse->cu_def, TT_CHECKPAINT, &editArea); + if (do_clear) SelectClear(); +} + /* Search function to delete paint. */ int diff --git a/select/select.h b/select/select.h index 7a3c1c29..ef6f2a68 100644 --- a/select/select.h +++ b/select/select.h @@ -51,6 +51,7 @@ extern int SelEnumLabelsMirror(); /* Procedures to operate on the selection. */ extern void SelectDelete(); +extern void SelectDeleteUses(); extern void SelectCopy(); extern void SelectTransform(); extern void SelectExpand();