<div class="gmail_quote">On Wed, Jul 4, 2012 at 6:52 PM, Michael O'Sullivan <span dir="ltr"><<a href="mailto:francium.duck@gmail.com" target="_blank">francium.duck@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div>On 4 July 2012 11:00, Michael O'Sullivan <<a href="mailto:francium.duck@gmail.com" target="_blank">francium.duck@gmail.com</a>> wrote:<br>
><br>
> On Jul 3, 2012 9:07 PM, "Sven Langkamp" <<a href="mailto:sven.langkamp@gmail.com" target="_blank">sven.langkamp@gmail.com</a>> wrote:<br>
>><br>
>> On Tue, Jul 3, 2012 at 9:07 PM, Michael O'Sullivan<br>
>> <<a href="mailto:francium.duck@gmail.com" target="_blank">francium.duck@gmail.com</a>> wrote:<br>
>>><br>
>>> Hello!<br>
>>><br>
>>> I'm very impressed with Krita, and would like to contribute. I've only<br>
>>> started looking at the source code today though, and I'm now feeling<br>
>>> rather stupid.<br>
>>><br>
>>> The scratch I'd like to itch is the following bug:<br>
>>> Bug 299844 - using a shape tool creates new shape layer even if shape<br>
>>> layer selected<br>
>>> <a href="https://bugs.kde.org/show_bug.cgi?id=299844" target="_blank">https://bugs.kde.org/show_bug.cgi?id=299844</a><br>
>>><br>
>>> I've found that the "draw a path" and "draw straight line with current<br>
>>> brush" tools don't seemed to be influenced by this bug, so I was<br>
>>> hoping to compare and contrast the implementations of these tools with<br>
>>> those of the ellipse and rectangle shape tools. The only problem is,<br>
>>> I'm not sure which files the "draw a path" and "draw straight line<br>
>>> with current brush" tools are implemented in the krita/ui/tools<br>
>>> directory. Can anyone point me in the right direction?<br>
>>><br>
>><br>
>> Welcome!<br>
>><br>
>> krita/ui/tools are just the base classes for tools. The specific tools are<br>
>> under krita/plugins/tools.<br>
>> The line and path tool are under krita/plugins/tools/defaulttools<br>
>> kis_tool_line and kis_tool_path<br>
>><br>
>> You might also have a look at ui/kis_shape_controller.cpp there is a<br>
>> method addShape that adds the new shape layer.<br>
>><br>
>> If you have questions you can also ask in the Krita IRC channel #krita on<br>
>> <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a><br>
>><br>
>> Good luck!<br>
>><br>
>> _______________________________________________<br>
>> kimageshop mailing list<br>
>> <a href="mailto:kimageshop@kde.org" target="_blank">kimageshop@kde.org</a><br>
>> <a href="https://mail.kde.org/mailman/listinfo/kimageshop" target="_blank">https://mail.kde.org/mailman/listinfo/kimageshop</a><br>
>><br>
><br>
> Thank you so much! This may take me a little while; I'm still working out<br>
> how it all fits together. I'll lurk on the irc channel :)<br>
><br>
> Michael<br>
<br>
</div></div>Hi there,<br>
<br>
Following Sven's helpful pointers I've been playing around with the<br>
source. I'm afraid there's still lots I don't understand.<br>
<br>
In the addShape method in ui/flake/kis_shape_controller.cpp there is a bool<br>
<br>
static inline bool belongsToShapeSelection(KoShape* shape) {<br>
    return dynamic_cast<KisShapeSelectionMarker*>(shape->userData());<br>
}<br>
<br>
that the method uses as a condition for the first if statement.<br>
<br>
if (belongsToShapeSelection(shape))<br>
// etc<br>
<br>
I don't understand what the method does with the returned pointer.<br>
<br></blockquote><div><br>The code simply checks if shape->userData() is a KisShapeSelectionMarker by interpreting the result of the dynamic cast as bool. If that's the case it knows that the shape belongs to a shape selection and not to a shape layer.<br>

 </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Following the program logic, it seems that using the rectangle and<br>
ellipse tool return a false to this first if statement anyway and<br>
instead we go to the else condition:<br>
<br>
} else {<br>
        KisShapeLayer *shapeLayer =<br>
dynamic_cast<KisShapeLayer*>(shape->parent());<br>
<br>
        if (!shapeLayer) {<br>
            KoShapeLayer *rootLayer = shapeForNode(image()->rootLayer().data());<br>
            shapeLayer = new KisShapeLayer(rootLayer, this, image(),<br>
                                           i18n("Vector Layer %1",<br>
m_d->nameServer->number()),<br>
                                           OPACITY_OPAQUE_U8);<br>
<br>
            image()->undoAdapter()->addCommand(new<br>
KisImageLayerAddCommand(image(), shapeLayer, image()->rootLayer(),<br>
image()->rootLayer()->childCount()));<br>
        }<br>
<br>
        shapeLayer->addShape(shape);<br>
    }<br>
<br>
So at the moment I'm working on the basis that the rectangle and<br>
ellipse tools are not setting a parent for the shape, despite a vector<br>
laying being selected upon drawing. By changing the string parameter<br>
for the new KisShapeLayer, I've established the if (!shapeLayer)<br>
condition evaluates as true for this bug. I've been going round and<br>
round in circles in the source and I'm not quite sure how to fix that.<br></blockquote><div><br>There are two possible cases. Either the parent is not set or it's not a KisShapeLayer. In both cases the dynamic cast fails and shapeLayer is 0.<br>

 </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I can see, for example, in the ellipse tool constructor there is a<br>
KoCanvasBase pointer parameter; and that the ellipse tool inherits<br>
from KisToolShape, which has an addShape method that uses the canvas<br>
parameter.<br>
<br>
I'm not sure how to set a shape parent from the canvas pointer (or<br>
even if this is the right approach). For instance, does the canvas<br>
pointer correlate to a layer anyway?<br></blockquote><div><br>The parent isn't explicitly set in the tool, but if a shape get added it will automatically get a parent.<br><br>You could check if the parent gets set, if it's the right parent or if there is a difference in the parent between a working and a non-working tool.<br>

Do you know how to use a debugger? You could simply put a breakpoint on line where the shape gets added in the tool and then step though the code from there.<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">


I'm probably trying to run before I can walk (or even crawl) at the<br>
moment, so apologies if this is all stupid! If anyone can give me an<br>
additional shove in the right direction that would be super!<br>
<br>
Many thanks,<br>
<br>
Michael<br>
<div><div>_______________________________________________<br>
kimageshop mailing list<br>
<a href="mailto:kimageshop@kde.org" target="_blank">kimageshop@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kimageshop" target="_blank">https://mail.kde.org/mailman/listinfo/kimageshop</a><br>
</div></div></blockquote></div><br>