ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Delete All Objects From the Current Layer

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
w2m Posted - Jun 04 2013 : 12:10:28
When using ImageEnVect is it possible to delete all objects on the current layer?

When you delete a layer the objects on the layer are not removed. ImageEnVect1.ObjectsCount is the same before and after a layer is deleted. Is this a bug or is there a way around this problem?

I tried this but it does not delete the objects on the current layer even though ImageEnVect1.RemoveObject(ihobj) was executed:
procedure TMainForm.DeleteLayer1Click(Sender: TObject);
{ Delete selected layer. }
var
  i: integer;
  j: integer;
  ihobj: integer;
  iobjLayer: integer;
begin
  { Select All objects in all layers }
  ImageEnVect1.SelAllObjects;
  for i := 0 to ImageEnVect1.LayersCount - 1 do
    for j := 0 to ImageEnVect1.SelObjectsCount - 1 do
    begin
      ihobj := ImageEnVect1.SelObjects[j];
      { if hobj is on current layer then delete the object }
      iobjLayer := ImageEnVect1.ObjLayer[ihobj];
      if iobjLayer = ImageEnVect1.LayersCurrent then
        ImageEnVect1.RemoveObject(ihobj);
    end;
  { Unselect All objects }
  ImageEnVect1.UnSelAllObjects;
  { Remove the current layer }
  ImageEnVect1.LayersRemove(ImageEnVect1.LayersCurrent);
  ImageEnVect1.Update;
  StatusBar1.Panels[2].Text := 'Objects: ' + IntToStr(ImageEnVect1.ObjectsCount);
  StatusBar1.Panels[5].Text := 'Layers: ' + IntToStr(ImageEnVect1.LayersCount);
end;

ImageEnVect1.ObjectsCount is the same before and after a layer is deleted with this code.

I suggest adding DeleteAllObjectsOnCurrentLayer method and to delete any objects on a layer before the layer is deleted and then set the ImageEnVect1.ObjectsCount.

Other good methods to add would be:
function ImageEnVect1.ObjectsCountOnLayer(ALayer: integer): integer;
procedure ImageEnVect1.SelAllObjectsOnLayer(ALayer: integer);
procedure ImageEnVect1.UnSelAllObjectsOnLayer(ALayer: integer);

William Miller
15   L A T E S T    R E P L I E S    (Newest First)
w2m Posted - Jun 15 2013 : 07:38:40
Pierre.

Send me your email address again... I lost it...
I will send you a temo that works perfectly with a text object in a layer.



William Miller
pierrotsc Posted - Jun 15 2013 : 07:07:14
Still does not work...very strange. Am i supposed to see the text in the layerView too? I do not. When i add text and i refresh the layer viewer, no text shows in the thumbnail. That could be unrelated though.

It still looks like the text is always anchored to layer 0.
when you wrote: "ImageEnVect1.LayersCurrent := iLayer; // This may be what you are missing "

I do not think so because when i add a new layer and i paint on it, i do paint on layer 1 and not 0.

I got to have some conflict in my code i guess somewhere.
maybe i should modify the layer demo and see if i can make it work here first.
Thanks.
P
w2m Posted - Jun 15 2013 : 06:52:33
Adding objects to a layer works perfectly here, so try this:
procedure TForm1.AddLayer1Click(Sender: TObject);
{ AddLayer1Click. }
var
  iLayer: integer;
begin
  ImageEnVect1.UnSelAllObjects;
  ImageEnVect1.Update;
  iLayer := ImageEnVect1.LayersAdd;
  ImageEnVect1.LayersCurrent := iLayer;  // This may be what you are missing  
  ImageEnVect1.CurrentLayer.VisibleBox := True;
  ImageEnVect1.CurrentLayer.Selectable := True;
  ImageEnVect1.LayersDrawBox := True;
  ImageEnVect1.ObjAnchorToLayers := AnchorObjToLayers1.Checked;
  ImageEnVect1.Layers[iLayer].Bitmap.AlphaChannel.Fill(0);
  ImageEnVect1.Layers[0].VisibleBox := False;
  ImageEnVect1.Layers[0].Selectable := True;
  ImageEnVect1.Layers[0].Locked := True;
  ImageEnVect1.Layers[iLayer].Name := AnsiString('Layer ' + IntToStr(iLayer));
    ImageEnVect1.MouseInteract := [miMoveLayers, miResizeLayers];
  ImageEnVect1.Update;
end;

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
pierrotsc Posted - Jun 15 2013 : 06:43:09
Just tried and no the text is still on layer 0 even with abjanchortolayers set to true in form create.

The new layer i add is transparent. So i modified my code just to add a new layer with a white background.
When I type some text and i click away, the text disappear. If i delete the layer, i see the text.
So really when I type, the text goes to layer 0 not layer 1.
P
w2m Posted - Jun 14 2013 : 19:27:14
Did you get it to work?





William Miller
pierrotsc Posted - Jun 14 2013 : 18:44:00
Sorry, i did not refresh my screen so i did not get your code. My mistake. Let me try..
Thanks.
w2m Posted - Jun 14 2013 : 18:41:36
Did you try the code I suggested?


William Miller
pierrotsc Posted - Jun 14 2013 : 18:30:56
I checked and the amount does not decrease. I have the property set to true in the formcreate.
w2m Posted - Jun 14 2013 : 17:41:17
Does this work? I did not test it though...
procedure TMainForm.aDeleteLayerExecute(Sender: TObject);
var
 i: integer;
 ihobj: Integer;
 iobjLayer: Integer;
begin
  if ImageEnVect1.LayersCurrent > 0 then // Do not do this or you can not delete objects in layer 0 unless this is what you want.
  begin
    for i := ImageEnVect1.ObjectsCount - 1 downto 0 do
    // Do not use
    //for ihobj := ImageEnVect1.ObjectsCount - 1 downto 0 do
    begin 
     // use GetObjFromIndex to get ihobj
      ihobj := ImageEnVect1.GetObjFromIndex(i);
      { if hobj is on current layer then delete the object }
      iobjLayer := ImageEnVect1.ObjLayer[ihobj];
      if iobjLayer = ImageEnVect1.LayersCurrent then
        ImageEnVect1.RemoveObject(ihobj);
    end;
  end;
 ImageEnVect1.LayersRemove(ImageEnVect1.LayersCurrent);
 ImageEnVect1.Update;
 RefreshLayerViewer;
 RefreshControls;
 end;
end;

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
pierrotsc Posted - Jun 14 2013 : 17:09:49
I have it set to false by default. I have to switch it to true before i start adding text.
This is the code when i delete the layer. The message is triggered but the text still stay.

procedure TMainForm.aDeleteLayerExecute(Sender: TObject);
var
ihobj: Integer;
iobjLayer: Integer;
begin
if imageenview.LayersCurrent > 0 then
begin
if imageenview.ObjAnchorToLayers then
showmessage('yes');
for ihobj := imageenview.ObjectsCount - 1 downto 0 do
begin
iobjLayer := imageenview.ObjLayer[ihobj];
if iobjLayer = imageenview.LayersCurrent then
imageenview.RemoveObject(ihobj);
end;
imageenview.LayersRemove(imageenview.LayersCurrent);
imageenview.Update;
RefreshLayerViewer;
RefreshControls;
end;
end;


I even added the statement to true in my formcreate...same thing.
Let me check the object count..
P
w2m Posted - Jun 14 2013 : 13:29:47
Are you adding a layer before you create the text object?
If you are adding objects to a layer > 0 you must call ImageEnVect1.ObjAnchorToLayers := True.

If you do not set ImageEnVect1.ObjAnchorToLayers := True when the Form is created or before you create any objects on a layer, the object's parent will be layer 0.

After you delete the object then remove the layer is the object you deleted present on layer 0?

Does the ObjectsCount decrease after you delete the object?
StatusBar1.Panels[2].Text := 'Objects: ' + IntToStr(ImageEnVect1.ObjectsCount);

My EBook includes an ImageEnVect demo that shows how to handle objects in layers.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
pierrotsc Posted - Jun 14 2013 : 12:54:57
I was wondering if adding text with miputtext is considered object material. I implemented the code above but when i add text to my layer and I delete it, the text is still there.
Just wondering if I am doing something wrong.
Thanks.
P
xequte Posted - Jun 07 2013 : 03:29:53


Sorry William,

That should read:

procedure TMainForm.DeleteLayer1Click(Sender: TObject);
{ Delete selected layer. }
var
  i : integer;
  ihobj: integer;
  iobjLayer: integer;
begin
  for i := ImageEnVect1.ObjectsCount - 1 downto 0 do
  begin
    ihobj := ImageEnVect1.GetObjFromIndex(i);
    { if hobj is on current layer then delete the object }
    iobjLayer := ImageEnVect1.ObjLayer[ihobj];
    if iobjLayer = ImageEnVect1.LayersCurrent then
      ImageEnVect1.RemoveObject(ihobj);
    end;
  { Remove the current layer }
  ImageEnVect1.LayersRemove(ImageEnVect1.LayersCurrent);
  ImageEnVect1.Update;
  StatusBar1.Panels[2].Text := 'Objects: ' + IntToStr(ImageEnVect1.ObjectsCount);
  StatusBar1.Panels[5].Text := 'Layers: ' + IntToStr(ImageEnVect1.LayersCount);
end;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
w2m Posted - Jun 05 2013 : 05:10:23
Thanks Nigel... I guess I did not take the correct approach...

William Miller
xequte Posted - Jun 05 2013 : 02:38:55
Hi William

How about the following (untested):

procedure TMainForm.DeleteLayer1Click(Sender: TObject);
{ Delete selected layer. }
var
  ihobj: integer;
  iobjLayer: integer;
begin
  for ihobj := ImageEnVect1.ObjectsCount - 1 downto 0 do
  begin
    { if hobj is on current layer then delete the object }
    iobjLayer := ImageEnVect1.ObjLayer[ihobj];
    if iobjLayer = ImageEnVect1.LayersCurrent then
      ImageEnVect1.RemoveObject(ihobj);
    end;
  { Remove the current layer }
  ImageEnVect1.LayersRemove(ImageEnVect1.LayersCurrent);
  ImageEnVect1.Update;
  StatusBar1.Panels[2].Text := 'Objects: ' + IntToStr(ImageEnVect1.ObjectsCount);
  StatusBar1.Panels[5].Text := 'Layers: ' + IntToStr(ImageEnVect1.LayersCount);
end;


We'll look into your suggestions for added functions.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com