Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

DescriptionToolDa, ToogleBaseSelect can't deselect

 Post Reply Post Reply
Author
Message
gr4ph0s View Drop Down
Member
Member


Joined: 2015 Jul 07
Location: France
Online Status: Online
Posts: 391
Post Options Post Options   Quote gr4ph0s Quote  Post ReplyReply Direct Link To This Post Topic: DescriptionToolDa, ToogleBaseSelect can't deselect
    Posted: 2017 Jun 11 at 6:14am

User Information:

Cinema 4D Version:    
Platform:      
Language(s):     C++  ;   

---------

I get a pretty weird behavior in my code. Toogle work for selecting but don't for deselecting.

I run my code in a drag event from a MouseInput function of a DescriptionToolData class.

// if we are in point snap mode
                if (snapResul.snapmode == SNAPMODE_POINT){

                    // if the target object is selected
                    if (objSelectedList->Find(snapResul.target) != NOTOK)
                    {
                        BaseContainer* kb_state = NewObjClear(BaseContainer);
                        if (!win->BfGetInputEvent(BFM_INPUT_KEYBOARD, kb_state))
                            _shift = false;

                        if (kb_state->GetInt32(BFM_INPUT_QUALIFIER) & QSHIFT)
                            _shift = true;
                        else
                            _shift = false;

                        PointObject* pobj = ToPoint(snapResul.target);
                        BaseSelect* bs = pobj->GetPointS();

                        if (_shift)
                        {
                            bs->Toggle(snapResul.component);
                        }
                        else
                        {
                            bs->DeselectAll();
                            bs->Select(snapResul.component);
                        }

                        DrawViews(DRAWFLAGS_ONLY_ACTIVE_VIEW | DRAWFLAGS_NO_THREAD | DRAWFLAGS_NO_ANIMATION);
                    }
                }

You can see the full code (and the full project here) => https://github.com/gr4ph0s/AxisConstraint/blob/master/source/tool/graph_constraint_snap.cpp

I also tested to replace Togle to Deselect. It don't work while if I remplace with Select it work perfectly.


Edited by gr4ph0s - 2017 Jun 11 at 6:22am
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1540
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jun 12 at 6:40am
Hi,

I tried to reproduce your issue here, using Select(), Deselect() and Toggle() in a DescriptionToolData plugin in MouseInput(), seem to work fine for me, doing exactly what I expected. So there must be something else in your code.

One more thing, completely unrelated: You have a memory leak in your code, as you are allocating but never free'ing the kb_state BaseContainer. You may want to use AutoAlloc there as well or just simply have the BaseContainer on stack.

Cheers,
Andreas
SDK Support Engineer
Back to Top
gr4ph0s View Drop Down
Member
Member


Joined: 2015 Jul 07
Location: France
Online Status: Online
Posts: 391
Post Options Post Options   Quote gr4ph0s Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jun 12 at 6:52am
Thanks for taking time to test. Gonna see what can I do and will back to you with more informations !

And thansk for the tips ! What the main difference beetwen AutoAlloc and AutoNew?
EDit:I Guess this thread explain it pretty well ! :p 
https://stackoverflow.com/questions/11256228/what-is-the-difference-between-class-new-and-class-alloc-init-in-ios


Edited by gr4ph0s - 2017 Jun 12 at 7:09am
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1540
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jun 13 at 2:37am
Hi,

no, the link does not provide a good explanation, as this is more a C4D related thing here.
I suggest to take a look a the Entity Creation manual.
Basically the AutoNew is behaving like a smart pointer on classes that can be instantiated via NewObj() (or in C++ standard new()), just calling the constructor of the class after allocation. Where AutoAlloc is thought for the more complex classes in Cinema 4D, where the initialization is done in Alloc() instead of the constructor.
Cheers,
Andreas
SDK Support Engineer
Back to Top
gr4ph0s View Drop Down
Member
Member


Joined: 2015 Jul 07
Location: France
Online Status: Online
Posts: 391
Post Options Post Options   Quote gr4ph0s Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jun 13 at 4:38am
I fel stupid...
The problem was prety obvious since I passed SNAPFLAG_IGNORE_SELECTED in my Snap function so that why it's failed.

Anyway thanks you a lot now I understand way more better how to handle my memory !
It would be nice to have all the manual listed in the index of the sdk. Even if a quick search with manual give it to you, I'm a lazy guy :p

But in all case thanks for your daily incredible work !
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1540
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jun 13 at 5:15am
Hi,

please don't feel stupid. I guess, almost everybody here in these forums has this kind of moments.

Thanks for the suggestion to improve the docs.
I will just need a bit more info. We know, our current search is not the nicest, especially as it can't do a full-text search on overviews and manuals. But at least the headings of the manuals are searched already. Now, which index would you want the manuals to be listed in? I mean, they are in the sidebar on the left under "Overviews", but I guess you know that already. Or is it about an alphabetical list without any grouping?

Cheers,
Andreas
SDK Support Engineer
Back to Top
gr4ph0s View Drop Down
Member
Member


Joined: 2015 Jul 07
Location: France
Online Status: Online
Posts: 391
Post Options Post Options   Quote gr4ph0s Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Jun 13 at 5:41am
Hehe fel stupid x2 I always tried to find manual and failed in General Information.

I only readed plugin development in overview (and to be honest I never clicked on overview so I didnt saw the index of overview which is way more explicit about manual are hidden here :p)

So I guess I get some good lecture for a week or two :D


Edited by gr4ph0s - 2017 Jun 13 at 6:31am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.