<commit_before>#include <stdio.h>
#include <stdlib.h>

int main()
{
    float fl,big;
    scanf("%f",&fl);
    big=fl;
    scanf("\n%f",&fl);
    if(big<fl)big=fl;
    scanf("\n%f",&fl);
    if(big<fl)big=fl;
    printf("%f",big);
    return 0;
}
<commit_msg>Update 02_BIGESTFLOAT_16TASK.C<commit_after>#include <stdio.h>
#include <stdlib.h>

int main()
{
    float fl,big;
    scanf("%f",&fl);
    big=fl;
    scanf("\n%f",&fl);
    if(big<fl)big=fl;
    scanf("\n%f",&fl);
    if(big<fl)big=fl;
    printf("%f.1",big);
    return 0;
}
<|endoftext|>


<commit_before>////////////////////////////////////////////////////////////////////////////////
//
//  Visual Leak Detector - Internal C++ Heap Management
//  Copyright (c) 2005-2011 Dan Moulding, Arkadiy Shapkin, Laurent Lessieux
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
//  See COPYING.txt for the full terms of the GNU Lesser General Public License.
//
////////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#define VLDBUILD     // Declares that we are building Visual Leak Detector.
#include "ntapi.h"   // Provides access to NT APIs.
#include "vldheap.h" // Provides access to VLD's internal heap data structures.
#undef new           // Do not map "new" to VLD's new operator in this file

// Global variables.
vldblockheader_t *vldblocklist = NULL; // List of internally allocated blocks on VLD's private heap.
HANDLE            vldheap;             // VLD's private heap.
CRITICAL_SECTION  vldheaplock;         // Serializes access to VLD's private heap.

// Local helper functions.
static inline void vlddelete (void *block);
static inline void* vldnew (size_t size, const char *file, int line);

// scalar delete operator - Delete operator used to free internally used memory
//   back to VLD's private heap.
//
//  - block (IN): Pointer to the scalar memory block to free.
//
//  Return Value:
//
//    None.
//
void operator delete (void *block)
{
    vlddelete(block);
}

// vector delete operator - Delete operator used to free internally used memory
//   back to VLD's private heap.
//
//  - block (IN): Pointer to the vector memory block to free.
//
//  Return Value:
//
//    None.
//
void operator delete [] (void *block)
{
    vlddelete(block);
}

// scalar delete operator - Delete operator used to free memory partially
//   allocated by new in the event that the corresponding new operator throws
//   an exception.
//
//  Note: This version of the delete operator should never be called directly.
//    The compiler automatically generates calls to this function as needed.
//
void operator delete (void *block, const char *, int)
{
    vlddelete(block);
}

// vector delete operator - Delete operator used to free memory partially
//   allocated by new in the event that the corresponding new operator throws
//   an exception.
//
//  Note: This version of the delete operator should never be called directly.
//    The compiler automatically generates calls to this function as needed.
//
void operator delete [] (void *block, const char *, int)
{
    vlddelete(block);
}

// scalar new operator - New operator used to allocate a scalar memory block
//   from VLD's private heap.
//
//  - size (IN): Size of the memory block to be allocated.
//
//  - file (IN): The name of the file from which this function is being
//      called.
//
//  - line (IN): The line number, in the above file, at which this function is
//      being called.
//
//  Return Value:
//
//    If the allocation succeeds, a pointer to the allocated memory block is
//    returned. If the allocation fails, NULL is returned.
//
void* operator new (size_t size, const char *file, int line)
{
    return vldnew(size, file, line);
}

// vector new operator - New operator used to allocate a vector memory block
//   from VLD's private heap.
//
//  - size (IN): Size of the memory block to be allocated.
//
//  - file (IN): The name of the file from which this function is being
//      called.
//
//  - line (IN): The line number, in the above file, at which this function is
//      being called.
//
//  Return Value:
//
//    If the allocation succeeds, a pointer to the allocated memory block is
//    returned. If the allocation fails, NULL is returned.
//
void* operator new [] (size_t size, const char *file, int line)
{
    return vldnew(size, file, line);
}

// vlddelete - Local helper function that actually frees memory back to VLD's
//   private heap.
//
//  - block (IN): Pointer to a memory block being freed.
//
//  Return Value:
//
//    None.
//
void vlddelete (void *block)
{
    BOOL              freed;
    vldblockheader_t *header = VLDBLOCKHEADER((LPVOID)block);

    // Unlink the block from the block list.
    EnterCriticalSection(&vldheaplock);
    if (header->prev) {
        header->prev->next = header->next;
    }
    else {
        vldblocklist = header->next;
    }

    if (header->next) {
        header->next->prev = header->prev;
    }
    LeaveCriticalSection(&vldheaplock);

    // Free the block.
    freed = RtlFreeHeap(vldheap, 0x0, header);
    assert(freed != FALSE);
}

// vldnew - Local helper function that actually allocates memory from VLD's
//   private heap. Prepends a header, which is used for bookeeping information
//   that allows VLD to detect and report internal memory leaks, to the returned
//   block, but the header is transparent to the caller because the returned
//   pointer points to the useable section of memory requested by the caller, it
//   does not point to the block header.
//
//  - size (IN): Size of the memory block to be allocated.
//
//  - file (IN): Name of the file that called the new operator.
//
//  - line (IN): Line, in the above file, at which the new operator was called.
//
//  Return Value:
//
//    If the memory allocation succeeds, a pointer to the allocated memory
//    block is returned. If the allocation fails, NULL is returned.
//
void* vldnew (size_t size, const char *file, int line)
{
    vldblockheader_t *header = (vldblockheader_t*)RtlAllocateHeap(vldheap, 0x0, size + sizeof(vldblockheader_t));
    static SIZE_T     serialnumber = 0;

    if (header == NULL) {
        // Out of memory.
        return NULL;
    }

    // Fill in the block's header information.
    header->file         = file;
    header->line         = line;
    header->serialnumber = serialnumber++;
    header->size         = size;

    // Link the block into the block list.
    EnterCriticalSection(&vldheaplock);
    header->next         = vldblocklist;
    if (header->next != NULL) {
        header->next->prev = header;
    }
    header->prev         = NULL;
    vldblocklist         = header;
    LeaveCriticalSection(&vldheaplock);

    // Return a pointer to the beginning of the data section of the block.
    return (void*)VLDBLOCKDATA(header);
}
<commit_msg>vlddelete bug fixed<commit_after>////////////////////////////////////////////////////////////////////////////////
//
//  Visual Leak Detector - Internal C++ Heap Management
//  Copyright (c) 2005-2011 Dan Moulding, Arkadiy Shapkin, Laurent Lessieux
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
//  See COPYING.txt for the full terms of the GNU Lesser General Public License.
//
////////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#define VLDBUILD     // Declares that we are building Visual Leak Detector.
#include "ntapi.h"   // Provides access to NT APIs.
#include "vldheap.h" // Provides access to VLD's internal heap data structures.
#undef new           // Do not map "new" to VLD's new operator in this file

// Global variables.
vldblockheader_t *vldblocklist = NULL; // List of internally allocated blocks on VLD's private heap.
HANDLE            vldheap;             // VLD's private heap.
CRITICAL_SECTION  vldheaplock;         // Serializes access to VLD's private heap.

// Local helper functions.
static inline void vlddelete (void *block);
static inline void* vldnew (size_t size, const char *file, int line);

// scalar delete operator - Delete operator used to free internally used memory
//   back to VLD's private heap.
//
//  - block (IN): Pointer to the scalar memory block to free.
//
//  Return Value:
//
//    None.
//
void operator delete (void *block)
{
    vlddelete(block);
}

// vector delete operator - Delete operator used to free internally used memory
//   back to VLD's private heap.
//
//  - block (IN): Pointer to the vector memory block to free.
//
//  Return Value:
//
//    None.
//
void operator delete [] (void *block)
{
    vlddelete(block);
}

// scalar delete operator - Delete operator used to free memory partially
//   allocated by new in the event that the corresponding new operator throws
//   an exception.
//
//  Note: This version of the delete operator should never be called directly.
//    The compiler automatically generates calls to this function as needed.
//
void operator delete (void *block, const char *, int)
{
    vlddelete(block);
}

// vector delete operator - Delete operator used to free memory partially
//   allocated by new in the event that the corresponding new operator throws
//   an exception.
//
//  Note: This version of the delete operator should never be called directly.
//    The compiler automatically generates calls to this function as needed.
//
void operator delete [] (void *block, const char *, int)
{
    vlddelete(block);
}

// scalar new operator - New operator used to allocate a scalar memory block
//   from VLD's private heap.
//
//  - size (IN): Size of the memory block to be allocated.
//
//  - file (IN): The name of the file from which this function is being
//      called.
//
//  - line (IN): The line number, in the above file, at which this function is
//      being called.
//
//  Return Value:
//
//    If the allocation succeeds, a pointer to the allocated memory block is
//    returned. If the allocation fails, NULL is returned.
//
void* operator new (size_t size, const char *file, int line)
{
    return vldnew(size, file, line);
}

// vector new operator - New operator used to allocate a vector memory block
//   from VLD's private heap.
//
//  - size (IN): Size of the memory block to be allocated.
//
//  - file (IN): The name of the file from which this function is being
//      called.
//
//  - line (IN): The line number, in the above file, at which this function is
//      being called.
//
//  Return Value:
//
//    If the allocation succeeds, a pointer to the allocated memory block is
//    returned. If the allocation fails, NULL is returned.
//
void* operator new [] (size_t size, const char *file, int line)
{
    return vldnew(size, file, line);
}

// vlddelete - Local helper function that actually frees memory back to VLD's
//   private heap.
//
//  - block (IN): Pointer to a memory block being freed.
//
//  Return Value:
//
//    None.
//
void vlddelete (void *block)
{
    if (block == NULL)
        return;

    BOOL              freed;
    vldblockheader_t *header = VLDBLOCKHEADER((LPVOID)block);

    // Unlink the block from the block list.
    EnterCriticalSection(&vldheaplock);
    if (header->prev) {
        header->prev->next = header->next;
    }
    else {
        vldblocklist = header->next;
    }

    if (header->next) {
        header->next->prev = header->prev;
    }
    LeaveCriticalSection(&vldheaplock);

    // Free the block.
    freed = RtlFreeHeap(vldheap, 0x0, header);
    assert(freed != FALSE);
}

// vldnew - Local helper function that actually allocates memory from VLD's
//   private heap. Prepends a header, which is used for bookeeping information
//   that allows VLD to detect and report internal memory leaks, to the returned
//   block, but the header is transparent to the caller because the returned
//   pointer points to the useable section of memory requested by the caller, it
//   does not point to the block header.
//
//  - size (IN): Size of the memory block to be allocated.
//
//  - file (IN): Name of the file that called the new operator.
//
//  - line (IN): Line, in the above file, at which the new operator was called.
//
//  Return Value:
//
//    If the memory allocation succeeds, a pointer to the allocated memory
//    block is returned. If the allocation fails, NULL is returned.
//
void* vldnew (size_t size, const char *file, int line)
{
    vldblockheader_t *header = (vldblockheader_t*)RtlAllocateHeap(vldheap, 0x0, size + sizeof(vldblockheader_t));
    static SIZE_T     serialnumber = 0;

    if (header == NULL) {
        // Out of memory.
        return NULL;
    }

    // Fill in the block's header information.
    header->file         = file;
    header->line         = line;
    header->serialnumber = serialnumber++;
    header->size         = size;

    // Link the block into the block list.
    EnterCriticalSection(&vldheaplock);
    header->next         = vldblocklist;
    if (header->next != NULL) {
        header->next->prev = header;
    }
    header->prev         = NULL;
    vldblocklist         = header;
    LeaveCriticalSection(&vldheaplock);

    // Return a pointer to the beginning of the data section of the block.
    return (void*)VLDBLOCKDATA(header);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: PaneDockingWindow.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2005-01-31 14:50:51 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#include "PaneDockingWindow.hxx"
#include "ViewShellBase.hxx"
#include "Window.hxx"
#include "sdresid.hxx"
#include "res_bmp.hrc"
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif
#include <vcl/toolbox.hxx>
#ifndef _SV_TASKPANELIST_HXX
#include <vcl/taskpanelist.hxx>
#endif

namespace sd {

PaneDockingWindow::PaneDockingWindow (
    SfxBindings *pBindings,
    SfxChildWindow *pChildWindow,
    ::Window* pParent,
    const ResId& rResId,
    PaneManager::PaneType ePane)
    : SfxDockingWindow (
        pBindings,
        pChildWindow,
        pParent,
        rResId
        ),
      mePane(ePane),
      msTitle(),
      mpTitleToolBox(NULL),
      maBorder (3,1,3,3),
      mnChildWindowId(pChildWindow->GetType())
{
    SetBackground (Wallpaper());

    InitializeTitleToolBox();

    ViewShellBase* pBase = ViewShellBase::GetViewShellBase(
        pBindings->GetDispatcher()->GetFrame());
    if (pBase != NULL)
    {
        msTitle = pBase->GetPaneManager().GetWindowTitle (mePane);
        pBase->GetPaneManager().SetWindow (mePane, this);
    }

    // Tell the system window about the new docking window so that it can be
    // reached via the keyboard.
    SystemWindow* pSystemWindow = GetSystemWindow();
    if (pSystemWindow != NULL)
        pSystemWindow->GetTaskPaneList()->AddWindow(this);
}

PaneDockingWindow::~PaneDockingWindow (void)
{
    ViewShellBase* pBase = ViewShellBase::GetViewShellBase(
        GetBindings().GetDispatcher()->GetFrame());

    // Tell the next system window that the docking window is no longer
    // available.
    SystemWindow* pSystemWindow = GetSystemWindow();
    if (pSystemWindow != NULL)
        pSystemWindow->GetTaskPaneList()->RemoveWindow(this);

    // Tell the ViewShellBase that the window of this slide sorter is not
    // available anymore.
    if (pBase != NULL)
        pBase->GetPaneManager().SetWindow (mePane, NULL);
}

void PaneDockingWindow::SetTitle (const String& rsTitle)
{
    msTitle = rsTitle;
    Invalidate();
}

void PaneDockingWindow::Resize (void)
{
    SfxDockingWindow::Resize();
    Size aWindowSize (GetOutputSizePixel());
    Size aToolBoxSize (0,0);
    int nTitleBarHeight (GetSettings().GetStyleSettings().GetTitleHeight());

    // Place the title tool box.
    if (mpTitleToolBox.get() != NULL)
    {
        if (IsFloatingMode())
            mpTitleToolBox->HideItem (1);
        else
            mpTitleToolBox->ShowItem (1);

        aToolBoxSize = mpTitleToolBox->CalcWindowSizePixel();
        if (aToolBoxSize.Height() > nTitleBarHeight)
            nTitleBarHeight = aToolBoxSize.Height();
        mpTitleToolBox->SetPosSizePixel (
            Point(aWindowSize.Width()-aToolBoxSize.Width(),
                (nTitleBarHeight-aToolBoxSize.Height())/2),
            aToolBoxSize);
    }

    // Place the view shell.
    ViewShellBase* pBase (ViewShellBase::GetViewShellBase(
        GetBindings().GetDispatcher()->GetFrame()));
    if (pBase != NULL)
    {
        ViewShell* pViewShell = pBase->GetPaneManager().GetViewShell (mePane);
        if (pViewShell != NULL)
        {
            ::sd::Window* pWindow = pViewShell->GetActiveWindow();
            if (nTitleBarHeight < aToolBoxSize.Height())
                nTitleBarHeight = aToolBoxSize.Height();
            aWindowSize.Height() -= nTitleBarHeight;
            pViewShell->Resize(
                Point(maBorder.Left(),nTitleBarHeight+maBorder.Top()),
                Size (aWindowSize.Width()-maBorder.Left()-maBorder.Right(),
                    aWindowSize.Height()-maBorder.Top()-maBorder.Bottom()));
        }
    }
}

void PaneDockingWindow::Paint (const Rectangle& rRectangle)
{
    SfxDockingWindow::Paint (rRectangle);
    int nTitleBarHeight (GetSettings().GetStyleSettings().GetTitleHeight());
    Size aToolBoxSize = mpTitleToolBox->CalcWindowSizePixel();
    if (aToolBoxSize.Height() > nTitleBarHeight)
        nTitleBarHeight = aToolBoxSize.Height();
    Color aOriginalLineColor (GetLineColor());
    Color aOriginalFillColor (GetFillColor());
    SetFillColor (GetSettings().GetStyleSettings().GetDialogColor());
    SetLineColor ();

    // Make font bold.
    const Font& rOriginalFont (GetFont());
    Font aFont (rOriginalFont);
    aFont.SetWeight (WEIGHT_BOLD);
    SetFont (aFont);

    // Set border values.
    Size aWindowSize (GetOutputSizePixel());
    int nOuterLeft = 0;
    int nInnerLeft = nOuterLeft + maBorder.Left() - 1;
    int nOuterRight = aWindowSize.Width() - 1;
    int nInnerRight = nOuterRight - maBorder.Right() + 1;
    int nInnerTop = nTitleBarHeight + maBorder.Top() - 1;
    int nOuterBottom = aWindowSize.Height() - 1;
    int nInnerBottom = nOuterBottom - maBorder.Bottom() + 1;

    // Paint title bar background.
    Rectangle aTitleBarBox (Rectangle(
        nOuterLeft,
        0,
        nOuterRight,
        nInnerTop-1));
    DrawRect (aTitleBarBox);

    if (nInnerLeft > nOuterLeft)
        DrawRect (
            Rectangle (nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom));
    if (nOuterRight > nInnerRight)
        DrawRect (
            Rectangle (nInnerRight, nInnerTop, nOuterRight, nInnerBottom));
    if (nInnerBottom < nOuterBottom)
        DrawRect (
            Rectangle (nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom));

    // Paint bevel border.
    SetFillColor ();
    SetLineColor (GetSettings().GetStyleSettings().GetShadowColor());
    if (maBorder.Top() > 0)
        DrawLine (
            Point(nInnerLeft,nInnerTop),
            Point(nInnerLeft,nInnerBottom));
    if (maBorder.Left() > 0)
        DrawLine (
            Point(nInnerLeft,nInnerTop),
            Point(nInnerRight,nInnerTop));
    SetLineColor (GetSettings().GetStyleSettings().GetLightColor());
    if (maBorder.Bottom() > 0)
        DrawLine (
            Point(nInnerRight,nInnerBottom),
            Point(nInnerLeft,nInnerBottom));
    if (maBorder.Right() > 0)
        DrawLine (
            Point(nInnerRight,nInnerBottom),
            Point(nInnerRight,nInnerTop));

    // Paint title bar text.
    SetLineColor (GetSettings().GetStyleSettings().GetActiveTextColor());
    SetFillColor ();
    aTitleBarBox.Left() += 3;
    DrawText (aTitleBarBox, msTitle,
        TEXT_DRAW_LEFT
        | TEXT_DRAW_VCENTER
        | TEXT_DRAW_MULTILINE
        | TEXT_DRAW_WORDBREAK);

    // Restore original values of the output device.
    SetFont (rOriginalFont);
    SetFillColor (aOriginalFillColor);
}

void PaneDockingWindow::InitializeTitleToolBox (void)
{
    if (mpTitleToolBox.get() == NULL)
    {
        // Initialize the title tool box.
        mpTitleToolBox.reset (new ToolBox(this));
        mpTitleToolBox->SetSelectHdl (
            LINK(this, PaneDockingWindow, ToolboxSelectHandler));
        mpTitleToolBox->SetOutStyle (TOOLBOX_STYLE_FLAT);
        mpTitleToolBox->SetBackground (Wallpaper (
            GetSettings().GetStyleSettings().GetDialogColor()));
        mpTitleToolBox->Show();
    }
    else
        mpTitleToolBox->Clear();

    // Get the closer bitmap and set it as right most button.
    Bitmap aBitmap (SdResId (BMP_CLOSE_DOC));
    Bitmap aBitmapHC (SdResId (BMP_CLOSE_DOC_H));
    Image aImage = Image (aBitmap, Color (COL_LIGHTMAGENTA));
    Image aImageHC = Image (aBitmapHC, Color (BMP_COLOR_HIGHCONTRAST));
    mpTitleToolBox->InsertItem (1,
        GetSettings().GetStyleSettings().GetMenuBarColor().IsDark()
        ? aImageHC
        : aImage);
    mpTitleToolBox->ShowItem (1);
}

USHORT PaneDockingWindow::AddMenu (
    const String& rsMenuName,
    ULONG nHelpId,
    const Link& rCallback)
{
    // Add the menu before the closer button.
    int nItemCount (mpTitleToolBox->GetItemCount());
    USHORT nItemId = nItemCount+1;
    mpTitleToolBox->InsertItem (
        nItemId,
        rsMenuName,
        TIB_DROPDOWN,
        nItemCount-1);
    mpTitleToolBox->SetHelpId( nItemId, nHelpId );
    mpTitleToolBox->SetClickHdl (rCallback);
    mpTitleToolBox->SetDropdownClickHdl (rCallback);

    return nItemCount+1;
}

IMPL_LINK(PaneDockingWindow, ToolboxSelectHandler, ToolBox*, pToolBox)
{
    USHORT nId = pToolBox->GetCurItemId();

    if (nId == 1)
    {
        EndTracking();
        SfxBoolItem aVisibility (mnChildWindowId, FALSE);
        GetBindings().GetDispatcher()->Execute (
            mnChildWindowId,
            SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
            &aVisibility,
            NULL);
    }

    return 0;
}

long PaneDockingWindow::Notify( NotifyEvent& rNEvt )
{
    return SfxDockingWindow::Notify (rNEvt);
}

void PaneDockingWindow::StateChanged( StateChangedType nType )
{
    switch (nType)
    {
        case STATE_CHANGE_INITSHOW:
            Resize();
            break;
    }
    SfxDockingWindow::StateChanged (nType);
}

void PaneDockingWindow::DataChanged( const DataChangedEvent& rDCEvt )
{
    SfxDockingWindow::DataChanged (rDCEvt);
}

} // end of namespace ::sd
<commit_msg>INTEGRATION: CWS toolbars4 (1.7.12); FILE MERGED 2005/02/16 14:42:47 cd 1.7.12.1: #i39612# Changed toolbox item style to TIB_DROPDOWNONLY<commit_after>/*************************************************************************
 *
 *  $RCSfile: PaneDockingWindow.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: obo $ $Date: 2005-03-15 09:19:16 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#include "PaneDockingWindow.hxx"
#include "ViewShellBase.hxx"
#include "Window.hxx"
#include "sdresid.hxx"
#include "res_bmp.hrc"
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif
#include <vcl/toolbox.hxx>
#ifndef _SV_TASKPANELIST_HXX
#include <vcl/taskpanelist.hxx>
#endif

namespace sd {

PaneDockingWindow::PaneDockingWindow (
    SfxBindings *pBindings,
    SfxChildWindow *pChildWindow,
    ::Window* pParent,
    const ResId& rResId,
    PaneManager::PaneType ePane)
    : SfxDockingWindow (
        pBindings,
        pChildWindow,
        pParent,
        rResId
        ),
      mePane(ePane),
      msTitle(),
      mpTitleToolBox(NULL),
      maBorder (3,1,3,3),
      mnChildWindowId(pChildWindow->GetType())
{
    SetBackground (Wallpaper());

    InitializeTitleToolBox();

    ViewShellBase* pBase = ViewShellBase::GetViewShellBase(
        pBindings->GetDispatcher()->GetFrame());
    if (pBase != NULL)
    {
        msTitle = pBase->GetPaneManager().GetWindowTitle (mePane);
        pBase->GetPaneManager().SetWindow (mePane, this);
    }

    // Tell the system window about the new docking window so that it can be
    // reached via the keyboard.
    SystemWindow* pSystemWindow = GetSystemWindow();
    if (pSystemWindow != NULL)
        pSystemWindow->GetTaskPaneList()->AddWindow(this);
}

PaneDockingWindow::~PaneDockingWindow (void)
{
    ViewShellBase* pBase = ViewShellBase::GetViewShellBase(
        GetBindings().GetDispatcher()->GetFrame());

    // Tell the next system window that the docking window is no longer
    // available.
    SystemWindow* pSystemWindow = GetSystemWindow();
    if (pSystemWindow != NULL)
        pSystemWindow->GetTaskPaneList()->RemoveWindow(this);

    // Tell the ViewShellBase that the window of this slide sorter is not
    // available anymore.
    if (pBase != NULL)
        pBase->GetPaneManager().SetWindow (mePane, NULL);
}

void PaneDockingWindow::SetTitle (const String& rsTitle)
{
    msTitle = rsTitle;
    Invalidate();
}

void PaneDockingWindow::Resize (void)
{
    SfxDockingWindow::Resize();
    Size aWindowSize (GetOutputSizePixel());
    Size aToolBoxSize (0,0);
    int nTitleBarHeight (GetSettings().GetStyleSettings().GetTitleHeight());

    // Place the title tool box.
    if (mpTitleToolBox.get() != NULL)
    {
        if (IsFloatingMode())
            mpTitleToolBox->HideItem (1);
        else
            mpTitleToolBox->ShowItem (1);

        aToolBoxSize = mpTitleToolBox->CalcWindowSizePixel();
        if (aToolBoxSize.Height() > nTitleBarHeight)
            nTitleBarHeight = aToolBoxSize.Height();
        mpTitleToolBox->SetPosSizePixel (
            Point(aWindowSize.Width()-aToolBoxSize.Width(),
                (nTitleBarHeight-aToolBoxSize.Height())/2),
            aToolBoxSize);
    }

    // Place the view shell.
    ViewShellBase* pBase (ViewShellBase::GetViewShellBase(
        GetBindings().GetDispatcher()->GetFrame()));
    if (pBase != NULL)
    {
        ViewShell* pViewShell = pBase->GetPaneManager().GetViewShell (mePane);
        if (pViewShell != NULL)
        {
            ::sd::Window* pWindow = pViewShell->GetActiveWindow();
            if (nTitleBarHeight < aToolBoxSize.Height())
                nTitleBarHeight = aToolBoxSize.Height();
            aWindowSize.Height() -= nTitleBarHeight;
            pViewShell->Resize(
                Point(maBorder.Left(),nTitleBarHeight+maBorder.Top()),
                Size (aWindowSize.Width()-maBorder.Left()-maBorder.Right(),
                    aWindowSize.Height()-maBorder.Top()-maBorder.Bottom()));
        }
    }
}

void PaneDockingWindow::Paint (const Rectangle& rRectangle)
{
    SfxDockingWindow::Paint (rRectangle);
    int nTitleBarHeight (GetSettings().GetStyleSettings().GetTitleHeight());
    Size aToolBoxSize = mpTitleToolBox->CalcWindowSizePixel();
    if (aToolBoxSize.Height() > nTitleBarHeight)
        nTitleBarHeight = aToolBoxSize.Height();
    Color aOriginalLineColor (GetLineColor());
    Color aOriginalFillColor (GetFillColor());
    SetFillColor (GetSettings().GetStyleSettings().GetDialogColor());
    SetLineColor ();

    // Make font bold.
    const Font& rOriginalFont (GetFont());
    Font aFont (rOriginalFont);
    aFont.SetWeight (WEIGHT_BOLD);
    SetFont (aFont);

    // Set border values.
    Size aWindowSize (GetOutputSizePixel());
    int nOuterLeft = 0;
    int nInnerLeft = nOuterLeft + maBorder.Left() - 1;
    int nOuterRight = aWindowSize.Width() - 1;
    int nInnerRight = nOuterRight - maBorder.Right() + 1;
    int nInnerTop = nTitleBarHeight + maBorder.Top() - 1;
    int nOuterBottom = aWindowSize.Height() - 1;
    int nInnerBottom = nOuterBottom - maBorder.Bottom() + 1;

    // Paint title bar background.
    Rectangle aTitleBarBox (Rectangle(
        nOuterLeft,
        0,
        nOuterRight,
        nInnerTop-1));
    DrawRect (aTitleBarBox);

    if (nInnerLeft > nOuterLeft)
        DrawRect (
            Rectangle (nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom));
    if (nOuterRight > nInnerRight)
        DrawRect (
            Rectangle (nInnerRight, nInnerTop, nOuterRight, nInnerBottom));
    if (nInnerBottom < nOuterBottom)
        DrawRect (
            Rectangle (nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom));

    // Paint bevel border.
    SetFillColor ();
    SetLineColor (GetSettings().GetStyleSettings().GetShadowColor());
    if (maBorder.Top() > 0)
        DrawLine (
            Point(nInnerLeft,nInnerTop),
            Point(nInnerLeft,nInnerBottom));
    if (maBorder.Left() > 0)
        DrawLine (
            Point(nInnerLeft,nInnerTop),
            Point(nInnerRight,nInnerTop));
    SetLineColor (GetSettings().GetStyleSettings().GetLightColor());
    if (maBorder.Bottom() > 0)
        DrawLine (
            Point(nInnerRight,nInnerBottom),
            Point(nInnerLeft,nInnerBottom));
    if (maBorder.Right() > 0)
        DrawLine (
            Point(nInnerRight,nInnerBottom),
            Point(nInnerRight,nInnerTop));

    // Paint title bar text.
    SetLineColor (GetSettings().GetStyleSettings().GetActiveTextColor());
    SetFillColor ();
    aTitleBarBox.Left() += 3;
    DrawText (aTitleBarBox, msTitle,
        TEXT_DRAW_LEFT
        | TEXT_DRAW_VCENTER
        | TEXT_DRAW_MULTILINE
        | TEXT_DRAW_WORDBREAK);

    // Restore original values of the output device.
    SetFont (rOriginalFont);
    SetFillColor (aOriginalFillColor);
}

void PaneDockingWindow::InitializeTitleToolBox (void)
{
    if (mpTitleToolBox.get() == NULL)
    {
        // Initialize the title tool box.
        mpTitleToolBox.reset (new ToolBox(this));
        mpTitleToolBox->SetSelectHdl (
            LINK(this, PaneDockingWindow, ToolboxSelectHandler));
        mpTitleToolBox->SetOutStyle (TOOLBOX_STYLE_FLAT);
        mpTitleToolBox->SetBackground (Wallpaper (
            GetSettings().GetStyleSettings().GetDialogColor()));
        mpTitleToolBox->Show();
    }
    else
        mpTitleToolBox->Clear();

    // Get the closer bitmap and set it as right most button.
    Bitmap aBitmap (SdResId (BMP_CLOSE_DOC));
    Bitmap aBitmapHC (SdResId (BMP_CLOSE_DOC_H));
    Image aImage = Image (aBitmap, Color (COL_LIGHTMAGENTA));
    Image aImageHC = Image (aBitmapHC, Color (BMP_COLOR_HIGHCONTRAST));
    mpTitleToolBox->InsertItem (1,
        GetSettings().GetStyleSettings().GetMenuBarColor().IsDark()
        ? aImageHC
        : aImage);
    mpTitleToolBox->ShowItem (1);
}

USHORT PaneDockingWindow::AddMenu (
    const String& rsMenuName,
    ULONG nHelpId,
    const Link& rCallback)
{
    // Add the menu before the closer button.
    int nItemCount (mpTitleToolBox->GetItemCount());
    USHORT nItemId = nItemCount+1;
    mpTitleToolBox->InsertItem (
        nItemId,
        rsMenuName,
        TIB_DROPDOWNONLY,
        nItemCount-1);
    mpTitleToolBox->SetHelpId( nItemId, nHelpId );
    mpTitleToolBox->SetClickHdl (rCallback);
    mpTitleToolBox->SetDropdownClickHdl (rCallback);

    return nItemCount+1;
}

IMPL_LINK(PaneDockingWindow, ToolboxSelectHandler, ToolBox*, pToolBox)
{
    USHORT nId = pToolBox->GetCurItemId();

    if (nId == 1)
    {
        EndTracking();
        SfxBoolItem aVisibility (mnChildWindowId, FALSE);
        GetBindings().GetDispatcher()->Execute (
            mnChildWindowId,
            SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
            &aVisibility,
            NULL);
    }

    return 0;
}

long PaneDockingWindow::Notify( NotifyEvent& rNEvt )
{
    return SfxDockingWindow::Notify (rNEvt);
}

void PaneDockingWindow::StateChanged( StateChangedType nType )
{
    switch (nType)
    {
        case STATE_CHANGE_INITSHOW:
            Resize();
            break;
    }
    SfxDockingWindow::StateChanged (nType);
}

void PaneDockingWindow::DataChanged( const DataChangedEvent& rDCEvt )
{
    SfxDockingWindow::DataChanged (rDCEvt);
}

} // end of namespace ::sd
<|endoftext|>


<commit_before>#include "todotxt.h"

TodotxtTask todotxt_parse_task(const char* todo, int id) {
    TodotxtTask task;

    task.id = id;
    task.finished = false;
    task.raw_todo = strdup(todo);

    //int clean_todo_start = 0;
    if (strlen(todo) > 2) {
        if (isupper(todo[1]) &&
            (todo[0] == '(' && todo[2] == ')' && todo[3] == ' ')) {
            task.priority = todo[1];
        } else {
            task.priority = '^';
        }
    }

    //task.todo = new char[strlen(todo) - clean_todo_start];

    return task;
}
<commit_msg>clean todo<commit_after>#include "todotxt.h"

TodotxtTask todotxt_parse_task(const char* todo, int id) {
    TodotxtTask task;

    task.id = id;
    task.finished = false;
    task.raw_todo = strdup(todo);

    int clean_todo_start = 0;
    if (strlen(todo) > 4) {
        if (isupper(todo[1]) &&
            (todo[0] == '(' && todo[2] == ')' && todo[3] == ' ')) {
            task.priority = todo[1];
            clean_todo_start = 4;
        } else {
            task.priority = '^';
        }
    }

    int todo_len = strlen(todo) - clean_todo_start;
    task.todo = new char[todo_len + 1];
    memcpy(task.todo, (todo + clean_todo_start), todo_len);

    return task;
}
<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkQtTreeView.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

#include "vtkQtTreeView.h"

#include <QHeaderView>
#include <QItemSelection>
#include <QTreeView>

#include "vtkAlgorithm.h"
#include "vtkAlgorithmOutput.h"
#include "vtkAnnotationLink.h"
#include "vtkConvertSelection.h"
#include "vtkDataRepresentation.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkQtTreeModelAdapter.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include "vtkTree.h"

vtkCxxRevisionMacro(vtkQtTreeView, "1.18");
vtkStandardNewMacro(vtkQtTreeView);

//----------------------------------------------------------------------------
vtkQtTreeView::vtkQtTreeView()
{
  this->TreeView = new QTreeView();
  this->TreeAdapter = new vtkQtTreeModelAdapter();
  this->TreeView->setModel(this->TreeAdapter);

  // Set up some default properties
  this->TreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
  this->TreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
  this->SetAlternatingRowColors(false);
  this->SetShowRootNode(false);
  this->Selecting = false;
  this->CurrentSelectionMTime = 0;

  // Drag/Drop parameters - defaults to off
  this->TreeView->setDragEnabled(false);
  this->TreeView->setDragDropMode(QAbstractItemView::DragOnly);
  this->TreeView->setDragDropOverwriteMode(false);
  this->TreeView->setAcceptDrops(false);
  this->TreeView->setDropIndicatorShown(false);

  QObject::connect(this->TreeView,
    SIGNAL(expanded(const QModelIndex&)),
    this, SIGNAL(expanded(const QModelIndex&)));
  QObject::connect(this->TreeView,
    SIGNAL(collapsed(const QModelIndex&)),
    this, SIGNAL(collapsed(const QModelIndex&)));

  QObject::connect(this->TreeView->selectionModel(),
      SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
      this,
      SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}

//----------------------------------------------------------------------------
vtkQtTreeView::~vtkQtTreeView()
{
  if(this->TreeView)
    {
    delete this->TreeView;
    }
  delete this->TreeAdapter;
}

//----------------------------------------------------------------------------
QWidget* vtkQtTreeView::GetWidget()
{
  return this->TreeView;
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetShowHeaders(bool state)
{
  if (state)
    {
    this->TreeView->header()->show();
    }
  else
    {
    this->TreeView->header()->hide();
    }
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetAlternatingRowColors(bool state)
{
  this->TreeView->setAlternatingRowColors(state);
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetEnableDragDrop(bool state)
{
  this->TreeView->setDragEnabled(state);
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetShowRootNode(bool state)
{
  if (!state)
    {
    this->TreeView->setRootIndex(this->TreeView->model()->index(0,0));
    }
  else
    {
    this->TreeView->setRootIndex(QModelIndex());
    }
}

//----------------------------------------------------------------------------
void vtkQtTreeView::HideColumn(int i)
{
  this->TreeView->hideColumn(i);
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetItemDelegate(QAbstractItemDelegate* delegate)
{
  this->TreeView->setItemDelegate(delegate);
}

//----------------------------------------------------------------------------
void vtkQtTreeView::AddInputConnection(
  vtkAlgorithmOutput* vtkNotUsed(conn), vtkAlgorithmOutput* vtkNotUsed(selectionConn))
{

}

//----------------------------------------------------------------------------
void vtkQtTreeView::RemoveInputConnection(
  vtkAlgorithmOutput* vtkNotUsed(conn), vtkAlgorithmOutput* vtkNotUsed(selectionConn))
{

}

//----------------------------------------------------------------------------
void vtkQtTreeView::slotQtSelectionChanged(const QItemSelection& vtkNotUsed(s1), const QItemSelection& vtkNotUsed(s2))
{
  this->Selecting = true;

  // Convert from a QModelIndexList to an index based vtkSelection
  const QModelIndexList qmil = this->TreeView->selectionModel()->selectedRows();
  vtkSelection *VTKIndexSelectList = this->TreeAdapter->QModelIndexListToVTKIndexSelection(qmil);

  // Convert to the correct type of selection
  vtkDataRepresentation* rep = this->GetRepresentation();
  vtkDataObject* data = this->TreeAdapter->GetVTKDataObject();
  vtkSmartPointer<vtkSelection> converted;
  converted.TakeReference(vtkConvertSelection::ToSelectionType(
    VTKIndexSelectList, data, rep->GetSelectionType(), rep->GetSelectionArrayNames()));

  // Call select on the representation (all 'linked' views will receive this selection)
  rep->Select(this, converted);

  this->Selecting = false;

  // Delete the selection list
  VTKIndexSelectList->Delete();

  // Store the selection mtime
  this->CurrentSelectionMTime = rep->GetAnnotationLink()->GetCurrentSelection()->GetMTime();
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetVTKSelection()
{
  // Make the selection current
  if (this->Selecting)
    {
    // If we initiated the selection, do nothing.
    return;
    }

  // Check to see we actually have data
  vtkDataObject *d = this->TreeAdapter->GetVTKDataObject();
  if (!d)
    {
    return;
    }

  // See if the selection has changed in any way
  vtkDataRepresentation* rep = this->GetRepresentation();
  vtkSelection* s = rep->GetAnnotationLink()->GetCurrentSelection();

  vtkSmartPointer<vtkSelection> selection;
  selection.TakeReference(vtkConvertSelection::ToSelectionType(
    s, d, vtkSelectionNode::INDICES, 0, vtkSelectionNode::VERTEX));

  QItemSelection qisList = this->TreeAdapter->
    VTKIndexSelectionToQItemSelection(selection);

  // Here we want the qt model to have it's selection changed
  // but we don't want to emit the selection.
  QObject::disconnect(this->TreeView->selectionModel(),
    SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
    this, SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));

  this->TreeView->selectionModel()->select(qisList,
    QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);

  QObject::connect(this->TreeView->selectionModel(),
   SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
   this, SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}

//----------------------------------------------------------------------------
void vtkQtTreeView::Update()
{
  vtkDataRepresentation* rep = this->GetRepresentation();
  if (!rep)
    {
    // Remove VTK data from the adapter
    this->TreeAdapter->SetVTKDataObject(0);
    this->TreeView->update();
    return;
    }
  rep->Update();

  // Make the data current
  vtkAlgorithm* alg = rep->GetInputConnection()->GetProducer();
  alg->Update();
  vtkDataObject *d = alg->GetOutputDataObject(0);
  vtkTree *tree = vtkTree::SafeDownCast(d);

  // Special-case: if our input is missing or not-a-tree, quietly exit.
  if(!tree)
    {
    //vtkErrorMacro("vtkQtTreeView requires a vtkTree as input");
    return;
    }

  // See if this is the same tree I already have
  if ((this->TreeAdapter->GetVTKDataObject() != tree) ||
      (this->TreeAdapter->GetVTKDataObjectMTime() != tree->GetMTime()))
    {
    this->TreeAdapter->SetVTKDataObject(tree);

    // Refresh the view
    this->TreeView->update();
    this->TreeView->expandAll();
    this->TreeView->resizeColumnToContents(0);
    this->TreeView->collapseAll();
    this->SetShowRootNode(false);
    }

  if(rep->GetAnnotationLink()->GetCurrentSelection()->GetMTime() !=
    this->CurrentSelectionMTime)
    {
    // Update the VTK selection
    this->SetVTKSelection();

    this->CurrentSelectionMTime =
      rep->GetAnnotationLink()->GetCurrentSelection()->GetMTime();
    }
}

//----------------------------------------------------------------------------
void vtkQtTreeView::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
}

<commit_msg>ENH: Ensure that selected items in tree are visible.<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkQtTreeView.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

#include "vtkQtTreeView.h"

#include <QHeaderView>
#include <QItemSelection>
#include <QTreeView>

#include "vtkAlgorithm.h"
#include "vtkAlgorithmOutput.h"
#include "vtkAnnotationLink.h"
#include "vtkConvertSelection.h"
#include "vtkDataRepresentation.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkQtTreeModelAdapter.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include "vtkTree.h"

vtkCxxRevisionMacro(vtkQtTreeView, "1.19");
vtkStandardNewMacro(vtkQtTreeView);

//----------------------------------------------------------------------------
vtkQtTreeView::vtkQtTreeView()
{
  this->TreeView = new QTreeView();
  this->TreeAdapter = new vtkQtTreeModelAdapter();
  this->TreeView->setModel(this->TreeAdapter);

  // Set up some default properties
  this->TreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
  this->TreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
  this->SetAlternatingRowColors(false);
  this->SetShowRootNode(false);
  this->Selecting = false;
  this->CurrentSelectionMTime = 0;

  // Drag/Drop parameters - defaults to off
  this->TreeView->setDragEnabled(false);
  this->TreeView->setDragDropMode(QAbstractItemView::DragOnly);
  this->TreeView->setDragDropOverwriteMode(false);
  this->TreeView->setAcceptDrops(false);
  this->TreeView->setDropIndicatorShown(false);

  QObject::connect(this->TreeView,
    SIGNAL(expanded(const QModelIndex&)),
    this, SIGNAL(expanded(const QModelIndex&)));
  QObject::connect(this->TreeView,
    SIGNAL(collapsed(const QModelIndex&)),
    this, SIGNAL(collapsed(const QModelIndex&)));

  QObject::connect(this->TreeView->selectionModel(),
      SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
      this,
      SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}

//----------------------------------------------------------------------------
vtkQtTreeView::~vtkQtTreeView()
{
  if(this->TreeView)
    {
    delete this->TreeView;
    }
  delete this->TreeAdapter;
}

//----------------------------------------------------------------------------
QWidget* vtkQtTreeView::GetWidget()
{
  return this->TreeView;
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetShowHeaders(bool state)
{
  if (state)
    {
    this->TreeView->header()->show();
    }
  else
    {
    this->TreeView->header()->hide();
    }
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetAlternatingRowColors(bool state)
{
  this->TreeView->setAlternatingRowColors(state);
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetEnableDragDrop(bool state)
{
  this->TreeView->setDragEnabled(state);
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetShowRootNode(bool state)
{
  if (!state)
    {
    this->TreeView->setRootIndex(this->TreeView->model()->index(0,0));
    }
  else
    {
    this->TreeView->setRootIndex(QModelIndex());
    }
}

//----------------------------------------------------------------------------
void vtkQtTreeView::HideColumn(int i)
{
  this->TreeView->hideColumn(i);
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetItemDelegate(QAbstractItemDelegate* delegate)
{
  this->TreeView->setItemDelegate(delegate);
}

//----------------------------------------------------------------------------
void vtkQtTreeView::AddInputConnection(
  vtkAlgorithmOutput* vtkNotUsed(conn), vtkAlgorithmOutput* vtkNotUsed(selectionConn))
{

}

//----------------------------------------------------------------------------
void vtkQtTreeView::RemoveInputConnection(
  vtkAlgorithmOutput* vtkNotUsed(conn), vtkAlgorithmOutput* vtkNotUsed(selectionConn))
{

}

//----------------------------------------------------------------------------
void vtkQtTreeView::slotQtSelectionChanged(const QItemSelection& vtkNotUsed(s1), const QItemSelection& vtkNotUsed(s2))
{
  this->Selecting = true;

  // Convert from a QModelIndexList to an index based vtkSelection
  const QModelIndexList qmil = this->TreeView->selectionModel()->selectedRows();
  vtkSelection *VTKIndexSelectList = this->TreeAdapter->QModelIndexListToVTKIndexSelection(qmil);

  // Convert to the correct type of selection
  vtkDataRepresentation* rep = this->GetRepresentation();
  vtkDataObject* data = this->TreeAdapter->GetVTKDataObject();
  vtkSmartPointer<vtkSelection> converted;
  converted.TakeReference(vtkConvertSelection::ToSelectionType(
    VTKIndexSelectList, data, rep->GetSelectionType(), rep->GetSelectionArrayNames()));

  // Call select on the representation (all 'linked' views will receive this selection)
  rep->Select(this, converted);

  this->Selecting = false;

  // Delete the selection list
  VTKIndexSelectList->Delete();

  // Store the selection mtime
  this->CurrentSelectionMTime = rep->GetAnnotationLink()->GetCurrentSelection()->GetMTime();
}

//----------------------------------------------------------------------------
void vtkQtTreeView::SetVTKSelection()
{
  // Make the selection current
  if (this->Selecting)
    {
    // If we initiated the selection, do nothing.
    return;
    }

  // Check to see we actually have data
  vtkDataObject *d = this->TreeAdapter->GetVTKDataObject();
  if (!d)
    {
    return;
    }

  // See if the selection has changed in any way
  vtkDataRepresentation* rep = this->GetRepresentation();
  vtkSelection* s = rep->GetAnnotationLink()->GetCurrentSelection();

  vtkSmartPointer<vtkSelection> selection;
  selection.TakeReference(vtkConvertSelection::ToSelectionType(
    s, d, vtkSelectionNode::INDICES, 0, vtkSelectionNode::VERTEX));

  QItemSelection qisList = this->TreeAdapter->
    VTKIndexSelectionToQItemSelection(selection);

  // Here we want the qt model to have it's selection changed
  // but we don't want to emit the selection.
  QObject::disconnect(this->TreeView->selectionModel(),
    SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
    this, SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));

  this->TreeView->selectionModel()->select(qisList,
    QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);

  QObject::connect(this->TreeView->selectionModel(),
   SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
   this, SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));

  // Make sure selected items are visible
  // FIXME: Should really recurse up all levels of the tree, this just does one.
  for(int i=0; i<qisList.size(); ++i)
    {
    this->TreeView->setExpanded(qisList[i].parent(), true);
    }
}

//----------------------------------------------------------------------------
void vtkQtTreeView::Update()
{
  vtkDataRepresentation* rep = this->GetRepresentation();
  if (!rep)
    {
    // Remove VTK data from the adapter
    this->TreeAdapter->SetVTKDataObject(0);
    this->TreeView->update();
    return;
    }
  rep->Update();

  // Make the data current
  vtkAlgorithm* alg = rep->GetInputConnection()->GetProducer();
  alg->Update();
  vtkDataObject *d = alg->GetOutputDataObject(0);
  vtkTree *tree = vtkTree::SafeDownCast(d);

  // Special-case: if our input is missing or not-a-tree, quietly exit.
  if(!tree)
    {
    //vtkErrorMacro("vtkQtTreeView requires a vtkTree as input");
    return;
    }

  // See if this is the same tree I already have
  if ((this->TreeAdapter->GetVTKDataObject() != tree) ||
      (this->TreeAdapter->GetVTKDataObjectMTime() != tree->GetMTime()))
    {
    this->TreeAdapter->SetVTKDataObject(tree);

    // Refresh the view
    this->TreeView->update();
    this->TreeView->expandAll();
    this->TreeView->resizeColumnToContents(0);
    this->TreeView->collapseAll();
    this->SetShowRootNode(false);
    }

  if(rep->GetAnnotationLink()->GetCurrentSelection()->GetMTime() !=
    this->CurrentSelectionMTime)
    {
    // Update the VTK selection
    this->SetVTKSelection();

    this->CurrentSelectionMTime =
      rep->GetAnnotationLink()->GetCurrentSelection()->GetMTime();
    }
}

//----------------------------------------------------------------------------
void vtkQtTreeView::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
}

<|endoftext|>


<commit_before>// $Id: PairExpRDFIntegrator_test.C,v 1.2 2000/09/02 16:19:23 anker Exp $
#include <BALL/CONCEPT/classTest.h>

///////////////////////////

// insert includes here
#include <BALL/SOLVATION/pairExpRDFIntegrator.h>

///////////////////////////

START_TEST(class_name, "$Id: PairExpRDFIntegrator_test.C,v 1.2 2000/09/02 16:19:23 anker Exp $")

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace std;
using namespace BALL;

///  insert tests for each member function here
///

// tests for class PairExpRDFIntegrator::

Coefficients coef;
vector<Coefficients> coefs;
vector<Interval> intervals;

coef.push_back(0.0); coef.push_back(0.0);
coef.push_back(0.0); coef.push_back(0.0);
coefs.push_back(coef);
coef.clear();

coef.push_back(3.0); coef.push_back(1.0);
coef.push_back(0.0); coef.push_back(0.0);
coefs.push_back(coef);
coef.clear();

coef.push_back(0.0); coef.push_back(0.0);
coef.push_back(0.0); coef.push_back(3.0);
coefs.push_back(coef);
coef.clear();

coef.push_back(2.0); coef.push_back(0.0);
coef.push_back(0.0); coef.push_back(0.0);
coefs.push_back(coef);
coef.clear();

intervals.push_back(Interval(0.0, 1.0));
intervals.push_back(Interval(1.0, 2.0));
intervals.push_back(Interval(2.0, 3.0));
intervals.push_back(Interval(3.0, INFINITY));

PiecewisePolynomial poly(4, intervals, coefs);
RadialDistributionFunction rdf(poly);

double alpha = 1;
double C1 = 1;
double C2 = 1;
double R_ij_o = 1;
double k1 = 0;
double k2 = 0;

PairExpRDFIntegrator* pointer;

CHECK(PairExpRDFIntegrator::PairExpRDFIntegrator())
  pointer = new PairExpRDFIntegrator();
	TEST_NOT_EQUAL(pointer, 0)
RESULT

CHECK(PairExpRDFIntegrator::~PairExpRDFIntegrator())
  delete pointer;
RESULT

CHECK(PairExpRDFIntegrator::PairExpRDFIntegrator(const PairExpRDFIntegrator& integrator))
	PairExpRDFIntegrator int1;
	int1.getRDF().setRepresentation(poly);
	int1.setConstants(alpha, C1, C2, R_ij_o, k1, k2);
	PairExpRDFIntegrator int2(int1);
	bool test = (int2.getRDF().getRepresentation().getIntervals() == intervals);
	TEST_EQUAL(test, true);
	test = (int2.getRDF().getRepresentation().getCoefficients() == coefs);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::PairExpRDFIntegrator(double alpha, double C1, double C2, double R_ij_o, double k1, double k2, const RadialDistributionFunction& rdf))
	PairExpRDFIntegrator integrator(alpha, C1, C2, R_ij_o, k1, k2, rdf);
	bool test = (integrator.getRDF().getRepresentation().getIntervals() == intervals);
	Log.info() << "Intervalle: " << rdf.getRepresentation().getIntervals().size() << endl;
	Log.info() << "Intervalle: " << integrator.getRDF().getRepresentation().getIntervals().size() << endl;
	TEST_EQUAL(test, true);
	test = (integrator.getRDF().getRepresentation().getCoefficients() == coefs);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::destroy())
	PairExpRDFIntegrator integrator(alpha, C1, C2, R_ij_o, k1, k2, rdf);
	integrator.destroy();
	vector<Interval> nope;
	bool test = (integrator.getRDF().getRepresentation().getIntervals() == nope);
	TEST_EQUAL(test, true);
	vector<Coefficients> naught;
	test = (integrator.getRDF().getRepresentation().getCoefficients() == naught);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::clear())
	PairExpRDFIntegrator integrator(alpha, C1, C2, R_ij_o, k1, k2, rdf);
	integrator.destroy();
	vector<Interval> nope;
	bool test = (integrator.getRDF().getRepresentation().getIntervals() == nope);
	TEST_EQUAL(test, true);
	vector<Coefficients> naught;
	test = (integrator.getRDF().getRepresentation().getCoefficients() == naught);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::set(const PairExpRDFIntegrator& integrator))
	PairExpRDFIntegrator int1;
	int1.getRDF().setRepresentation(poly);
	int1.setConstants(alpha, C1, C2, R_ij_o, k1, k2);
	PairExpRDFIntegrator int2;
	int2.set(int1);
	bool test = (int2.getRDF().getRepresentation().getIntervals() == intervals);
	TEST_EQUAL(test, true);
	test = (int2.getRDF().getRepresentation().getCoefficients() == coefs);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::PairExpRDFIntegrator& operator =
			(const PairExpRDFIntegrator& integrator))
	PairExpRDFIntegrator int1;
	int1.getRDF().setRepresentation(poly);
	int1.setConstants(alpha, C1, C2, R_ij_o, k1, k2);
	PairExpRDFIntegrator int2;
	int2 = int1;
	bool test = (int2.getRDF().getRepresentation().getIntervals() == intervals);
	TEST_EQUAL(test, true);
	test = (int2.getRDF().getRepresentation().getCoefficients() == coefs);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::setConstants(double alpha, double C1, double C2, double R_ij_o, double k1, double k2))
  //BAUSTELLE
RESULT

CHECK(PairExpRDFIntegrator::integrateToInf(double from) const )
	PairExpRDFIntegrator integrator(1, 1, 1, 1, 0, 0, rdf);
	double val;
	val = integrator.integrateToInf(3);
	TEST_REAL_EQUAL(val, 0.097928046)
  //BAUSTELLE
RESULT

CHECK(PairExpRDFIntegrator::integrateToInf(double from, double alpha, double C1, double C2, double R_ij_o, double k1, double k2))
	PairExpRDFIntegrator integrator(1, 1, 1, 1, 0, 0, rdf);
  //BAUSTELLE
RESULT

CHECK(PairExpRDFIntegrator::integrate(double from, double to) const )
	PairExpRDFIntegrator integrator(1, 1, 1, 1, 0, 0, rdf);
	integrator.setRDF(rdf);
	double val;
	val = integrator.integrate(0.0, 1.0);
	TEST_REAL_EQUAL(val, 0.0)
	val = integrator.integrate(1.0, 1.5);
	TEST_REAL_EQUAL(val, -0.080510343)
	val = integrator.integrate(2.3, 2.7);
	TEST_REAL_EQUAL(val, 0.0042484315)
	val = integrator.integrate(1.3, 2.3);
	TEST_REAL_EQUAL(val, 0.3282713538)
RESULT

CHECK(PairExpRDFIntegrator::integrate(double from, double to, double alpha, double C1, double C2, double R_ij_o, double k1, double k2))
	// Zuerst der triviale Test (keine geometrische Korrektur)
	PairExpRDFIntegrator integrator(0, 0, 0, 0, 0, 0, rdf);
	integrator.setRDF(rdf);
	double val;
	val = integrator.integrate(0.1, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0);
	TEST_REAL_EQUAL(val, 0.0)
	val = integrator.integrate(1.0, 1.5, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0);
	TEST_REAL_EQUAL(val, -0.080510343)
	val = integrator.integrate(2.3, 2.7, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0);
	TEST_REAL_EQUAL(val, 0.012745294)
	val = integrator.integrate(1.3, 2.3, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0);
	TEST_REAL_EQUAL(val, 0.3282713538)

	val = integrator.integrate(0.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
	TEST_REAL_EQUAL(val, 0.0)
	val = integrator.integrate(1.0, 1.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
	TEST_REAL_EQUAL(val, -0.1022999316)
RESULT

CHECK(PairExpRDFIntegrator::double operator () (double x) const )
  //BAUSTELLE
RESULT

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
<commit_msg>fixed: values of the numerical integration should be ok now<commit_after>// $Id: PairExpRDFIntegrator_test.C,v 1.3 2000/09/19 09:29:00 anker Exp $
#include <BALL/CONCEPT/classTest.h>

///////////////////////////

// insert includes here
#include <BALL/SOLVATION/pairExpRDFIntegrator.h>

///////////////////////////

START_TEST(class_name, "$Id: PairExpRDFIntegrator_test.C,v 1.3 2000/09/19 09:29:00 anker Exp $")

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace std;
using namespace BALL;

///  insert tests for each member function here
///

// tests for class PairExpRDFIntegrator::

Coefficients coef;
vector<Coefficients> coefs;
vector<Interval> intervals;

coef.push_back(0.0); coef.push_back(0.0);
coef.push_back(0.0); coef.push_back(0.0);
coefs.push_back(coef);
coef.clear();

coef.push_back(3.0); coef.push_back(1.0);
coef.push_back(0.0); coef.push_back(0.0);
coefs.push_back(coef);
coef.clear();

coef.push_back(0.0); coef.push_back(0.0);
coef.push_back(0.0); coef.push_back(3.0);
coefs.push_back(coef);
coef.clear();

coef.push_back(2.0); coef.push_back(0.0);
coef.push_back(0.0); coef.push_back(0.0);
coefs.push_back(coef);
coef.clear();

intervals.push_back(Interval(0.0, 1.0));
intervals.push_back(Interval(1.0, 2.0));
intervals.push_back(Interval(2.0, 3.0));
intervals.push_back(Interval(3.0, INFINITY));

PiecewisePolynomial poly(4, intervals, coefs);
RadialDistributionFunction rdf(poly);

double alpha = 1;
double C1 = 1;
double C2 = 1;
double R_ij_o = 1;
double k1 = 0;
double k2 = 0;

PairExpRDFIntegrator* pointer;

CHECK(PairExpRDFIntegrator::PairExpRDFIntegrator())
  pointer = new PairExpRDFIntegrator();
	TEST_NOT_EQUAL(pointer, 0)
RESULT

CHECK(PairExpRDFIntegrator::~PairExpRDFIntegrator())
  delete pointer;
RESULT

CHECK(PairExpRDFIntegrator::PairExpRDFIntegrator(const PairExpRDFIntegrator& integrator))
	PairExpRDFIntegrator int1;
	int1.getRDF().setRepresentation(poly);
	int1.setConstants(alpha, C1, C2, R_ij_o, k1, k2);
	PairExpRDFIntegrator int2(int1);
	bool test = (int2.getRDF().getRepresentation().getIntervals() == intervals);
	TEST_EQUAL(test, true);
	test = (int2.getRDF().getRepresentation().getCoefficients() == coefs);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::PairExpRDFIntegrator(double alpha, double C1, double C2, double R_ij_o, double k1, double k2, const RadialDistributionFunction& rdf))
	PairExpRDFIntegrator integrator(alpha, C1, C2, R_ij_o, k1, k2, rdf);
	bool test = (integrator.getRDF().getRepresentation().getIntervals() == intervals);
	Log.info() << "Intervalle: " << rdf.getRepresentation().getIntervals().size() << endl;
	Log.info() << "Intervalle: " << integrator.getRDF().getRepresentation().getIntervals().size() << endl;
	TEST_EQUAL(test, true);
	test = (integrator.getRDF().getRepresentation().getCoefficients() == coefs);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::destroy())
	PairExpRDFIntegrator integrator(alpha, C1, C2, R_ij_o, k1, k2, rdf);
	integrator.destroy();
	vector<Interval> nope;
	bool test = (integrator.getRDF().getRepresentation().getIntervals() == nope);
	TEST_EQUAL(test, true);
	vector<Coefficients> naught;
	test = (integrator.getRDF().getRepresentation().getCoefficients() == naught);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::clear())
	PairExpRDFIntegrator integrator(alpha, C1, C2, R_ij_o, k1, k2, rdf);
	integrator.destroy();
	vector<Interval> nope;
	bool test = (integrator.getRDF().getRepresentation().getIntervals() == nope);
	TEST_EQUAL(test, true);
	vector<Coefficients> naught;
	test = (integrator.getRDF().getRepresentation().getCoefficients() == naught);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::set(const PairExpRDFIntegrator& integrator))
	PairExpRDFIntegrator int1;
	int1.getRDF().setRepresentation(poly);
	int1.setConstants(alpha, C1, C2, R_ij_o, k1, k2);
	PairExpRDFIntegrator int2;
	int2.set(int1);
	bool test = (int2.getRDF().getRepresentation().getIntervals() == intervals);
	TEST_EQUAL(test, true);
	test = (int2.getRDF().getRepresentation().getCoefficients() == coefs);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::PairExpRDFIntegrator& operator =
			(const PairExpRDFIntegrator& integrator))
	PairExpRDFIntegrator int1;
	int1.getRDF().setRepresentation(poly);
	int1.setConstants(alpha, C1, C2, R_ij_o, k1, k2);
	PairExpRDFIntegrator int2;
	int2 = int1;
	bool test = (int2.getRDF().getRepresentation().getIntervals() == intervals);
	TEST_EQUAL(test, true);
	test = (int2.getRDF().getRepresentation().getCoefficients() == coefs);
	TEST_EQUAL(test, true);
	// BAUSTELLE: Konstanten
	// BAUSTELLE: false, Spezialflle
RESULT

CHECK(PairExpRDFIntegrator::setConstants(double alpha, double C1, double C2, double R_ij_o, double k1, double k2))
  //BAUSTELLE
RESULT

CHECK(PairExpRDFIntegrator::integrateToInf(double from) const )
	PairExpRDFIntegrator integrator(1, 1, 1, 1, 0, 0, rdf);
	double val;

	PRECISION(0.01)

	val = integrator.integrateToInf(3);
	double rel_err = fabs((val - 1.66807) / 1.66807);
	TEST_REAL_EQUAL(rel_err, 0.01);
  //BAUSTELLE
RESULT

CHECK(PairExpRDFIntegrator::integrateToInf(double from, double alpha, double C1, double C2, double R_ij_o, double k1, double k2))
	PairExpRDFIntegrator integrator(1, 1, 1, 1, 0, 0, rdf);
  //BAUSTELLE
RESULT

CHECK(PairExpRDFIntegrator::integrate(double from, double to) const )
	PairExpRDFIntegrator integrator(1, 1, 1, 1, 0, 0, rdf);
	integrator.setRDF(rdf);
	double val;
	// val = integrator.integrate(0.0, 1.0);
	// TEST_REAL_EQUAL(val, 0.0)
	// val = integrator.integrate(1.0, 1.5);
	// TEST_REAL_EQUAL(val, -0.080510343)
	// val = integrator.integrate(2.3, 2.7);
	// TEST_REAL_EQUAL(val, 0.0042484315)
	// val = integrator.integrate(1.3, 2.3);
	// TEST_REAL_EQUAL(val, 0.3282713538)
RESULT

CHECK(PairExpRDFIntegrator::integrate(double from, double to, double alpha, double C1, double C2, double R_ij_o, double k1, double k2))

	// Zuerst der triviale Test (keine geometrische Korrektur)
	PairExpRDFIntegrator integrator(0, 0, 0, 0, 0, 0, rdf);
	integrator.setRDF(rdf);
	integrator.options.readOptionFile("integrator.options");
	double val;
	double rel_err;

	PRECISION(0.01)

	val = integrator.integrate(0.1, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0);
	TEST_REAL_EQUAL(val, 0.0)
	val = integrator.integrate(1.0, 1.5, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0);
	rel_err = fabs((val - (-0.080510343)) / -0.080510343);
	TEST_REAL_EQUAL(rel_err, 0.01);
	val = integrator.integrate(2.3, 2.7, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0);
	rel_err = fabs((val - 0.012745294) / 0.012745294);
	TEST_REAL_EQUAL(rel_err, 0.01);
	val = integrator.integrate(1.3, 2.3, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0);
	rel_err = fabs((val - 0.3282713538) / 0.3282713538);
	TEST_REAL_EQUAL(rel_err, 0.01);

	// now come the tests involving geometric correction (and therefore
	// numerical integration)

	// val = integrator.integrate(0.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
	// TEST_REAL_EQUAL(val, 0.0)

	// these limits correspond to 1.5 .. 1.7 as argument for the rdf.
	val = integrator.integrate(0.72474, 0.96287, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
	rel_err = fabs((val - (-1.53602))/ -1.53602);
	TEST_REAL_EQUAL(rel_err, 0.01);
	// these limits correspond to 1.7 .. 1.9 as argument for the rdf.
	val = integrator.integrate(0.96287, 1.19115, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
	rel_err = fabs((val - (-0.32462))/ -0.32462);
	TEST_REAL_EQUAL(rel_err, 0.01);

	// now the same with some k1
	val = integrator.integrate(0.37038, 0.53470, 1.0, 1.0, 1.0, 1.0, 3.0, 1.0);
	rel_err = fabs((val - (-15.50386))/ -15.50386);
	TEST_REAL_EQUAL(rel_err, 0.01);
	val = integrator.integrate(0.53470, 0.70454, 1.0, 1.0, 1.0, 1.0, 3.0, 1.0);
	Log.info() << val;
	rel_err = fabs((val - (-4.50856))/ -4.50856);
	TEST_REAL_EQUAL(rel_err, 0.01);

	// now the same with some k1 and k2
	val = integrator.integrate(0.08113, 0.27200, 1.0, 1.0, 1.0, 1.0, 3.0, 2.0);
	rel_err = fabs((val - (-2147.68792)) / -2147.68792);
	TEST_REAL_EQUAL(rel_err, 0.01);
	val = integrator.integrate(0.27200, 0.46469, 1.0, 1.0, 1.0, 1.0, 3.0, 2.0);
	rel_err = fabs((val - (-49.80145)) / -49.80145);
	TEST_REAL_EQUAL(rel_err, 0.01);
RESULT

CHECK(PairExpRDFIntegrator::double operator () (double x) const )
  //BAUSTELLE
RESULT

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
<|endoftext|>


<commit_before>//
// Aspia Project
// Copyright (C) 2018 Dmitry Chapyshev <dmitry@aspia.ru>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#include "client/ui/file_manager_window.h"

#include <QDebug>

#include "client/ui/address_bar_model.h"
#include "client/ui/file_remove_dialog.h"
#include "client/ui/file_transfer_dialog.h"
#include "client/ui/file_manager_settings.h"
#include "client/ui/file_mime_data.h"

namespace aspia {

FileManagerWindow::FileManagerWindow(ConnectData* connect_data, QWidget* parent)
    : QWidget(parent)
{
    ui.setupUi(this);

    QString computer_name;
    if (!connect_data->computerName().isEmpty())
        computer_name = connect_data->computerName();
    else
        computer_name = connect_data->address();

    setWindowTitle(tr("%1 - Aspia File Transfer").arg(computer_name));

    FileManagerSettings settings;
    restoreGeometry(settings.windowGeometry());

    ui.splitter->restoreState(settings.splitterState());

    QString mime_type = FileMimeData::createMimeType();

    ui.local_panel->setPanelName(tr("Local Computer"));
    ui.local_panel->setMimeType(mime_type);
    ui.local_panel->setDriveListState(settings.localDriveListState());
    ui.local_panel->setFileListState(settings.localFileListState());

    ui.remote_panel->setPanelName(tr("Remote Computer"));
    ui.remote_panel->setMimeType(mime_type);
    ui.remote_panel->setDriveListState(settings.remoteDriveListState());
    ui.remote_panel->setFileListState(settings.remoteFileListState());

    connect(ui.local_panel, &FilePanel::removeItems, this, &FileManagerWindow::removeItems);
    connect(ui.remote_panel, &FilePanel::removeItems, this, &FileManagerWindow::removeItems);
    connect(ui.local_panel, &FilePanel::sendItems, this, &FileManagerWindow::sendItems);
    connect(ui.remote_panel, &FilePanel::sendItems, this, &FileManagerWindow::sendItems);
    connect(ui.local_panel, &FilePanel::receiveItems, this, &FileManagerWindow::receiveItems);
    connect(ui.remote_panel, &FilePanel::receiveItems, this, &FileManagerWindow::receiveItems);
    connect(ui.local_panel, &FilePanel::newRequest, this, &FileManagerWindow::localRequest);
    connect(ui.remote_panel, &FilePanel::newRequest, this, &FileManagerWindow::remoteRequest);
    connect(ui.local_panel, &FilePanel::pathChanged, this, &FileManagerWindow::onPathChanged);
    connect(ui.remote_panel, &FilePanel::pathChanged, this, &FileManagerWindow::onPathChanged);
}

void FileManagerWindow::refresh()
{
    ui.local_panel->refresh();
    ui.remote_panel->refresh();
}

void FileManagerWindow::closeEvent(QCloseEvent* event)
{
    FileManagerSettings settings;

    settings.setWindowGeometry(saveGeometry());
    settings.setSplitterState(ui.splitter->saveState());

    ui.local_panel->updateState();
    settings.setLocalDriveListState(ui.local_panel->driveListState());
    settings.setLocalFileListState(ui.local_panel->fileListState());

    ui.remote_panel->updateState();
    settings.setRemoteDriveListState(ui.remote_panel->driveListState());
    settings.setRemoteFileListState(ui.remote_panel->fileListState());

    emit windowClose();
    QWidget::closeEvent(event);
}

void FileManagerWindow::removeItems(FilePanel* sender, const QList<FileRemover::Item>& items)
{
    FileRemoveDialog* progress_dialog = new FileRemoveDialog(this);
    FileRemover* remover = new FileRemover(progress_dialog);

    if (sender == ui.local_panel)
    {
        connect(remover, &FileRemover::newRequest, this, &FileManagerWindow::localRequest);
    }
    else
    {
        Q_ASSERT(sender == ui.remote_panel);
        connect(remover, &FileRemover::newRequest, this, &FileManagerWindow::remoteRequest);
    }

    connect(remover, &FileRemover::started, progress_dialog, &FileRemoveDialog::open);
    connect(remover, &FileRemover::finished, progress_dialog, &FileRemoveDialog::close);
    connect(remover, &FileRemover::finished, sender, &FilePanel::refresh);

    connect(remover, &FileRemover::progressChanged,
            progress_dialog, &FileRemoveDialog::setProgress);

    connect(remover, &FileRemover::error, progress_dialog, &FileRemoveDialog::showError);

    connect(progress_dialog, &FileRemoveDialog::finished,
            progress_dialog, &FileRemoveDialog::deleteLater);

    connect(this, &FileManagerWindow::windowClose, progress_dialog, &FileRemoveDialog::close);

    remover->start(sender->currentPath(), items);
}

void FileManagerWindow::sendItems(FilePanel* sender, const QList<FileTransfer::Item>& items)
{
    if (sender == ui.local_panel)
    {
        transferItems(FileTransfer::Uploader,
                      ui.local_panel->currentPath(),
                      ui.remote_panel->currentPath(),
                      items);
    }
    else
    {
        Q_ASSERT(sender == ui.remote_panel);

        transferItems(FileTransfer::Downloader,
                      ui.remote_panel->currentPath(),
                      ui.local_panel->currentPath(),
                      items);
    }
}

void FileManagerWindow::receiveItems(FilePanel* sender,
                                     const QString& target_folder,
                                     const QList<FileTransfer::Item>& items)
{
    if (sender == ui.local_panel)
    {
        transferItems(FileTransfer::Downloader,
                      ui.remote_panel->currentPath(),
                      target_folder,
                      items);
    }
    else
    {
        Q_ASSERT(sender == ui.remote_panel);

        transferItems(FileTransfer::Uploader,
                      ui.local_panel->currentPath(),
                      target_folder,
                      items);
    }
}

void FileManagerWindow::transferItems(FileTransfer::Type type,
                                      const QString& source_path,
                                      const QString& target_path,
                                      const QList<FileTransfer::Item>& items)
{
    FileTransferDialog* dialog = new FileTransferDialog(this);
    FileTransfer* transfer = new FileTransfer(type, dialog);

    if (type == FileTransfer::Uploader)
    {
        connect(transfer, &FileTransfer::finished, ui.remote_panel, &FilePanel::refresh);
    }
    else
    {
        Q_ASSERT(type == FileTransfer::Downloader);
        connect(transfer, &FileTransfer::finished, ui.local_panel, &FilePanel::refresh);
    }

    connect(transfer, &FileTransfer::started, dialog, &FileTransferDialog::open);
    connect(transfer, &FileTransfer::finished, dialog, &FileTransferDialog::onTransferFinished);

    connect(transfer, &FileTransfer::currentItemChanged, dialog, &FileTransferDialog::setCurrentItem);
    connect(transfer, &FileTransfer::progressChanged, dialog, &FileTransferDialog::setProgress);

    connect(transfer, &FileTransfer::error, dialog, &FileTransferDialog::showError);
    connect(transfer, &FileTransfer::localRequest, this, &FileManagerWindow::localRequest);
    connect(transfer, &FileTransfer::remoteRequest, this, &FileManagerWindow::remoteRequest);

    connect(dialog, &FileTransferDialog::transferCanceled, transfer, &FileTransfer::stop);
    connect(dialog, &FileTransferDialog::finished, dialog, &FileTransferDialog::deleteLater);

    connect(this, &FileManagerWindow::windowClose, dialog, &FileTransferDialog::close);

    transfer->start(source_path, target_path, items);
}

void FileManagerWindow::onPathChanged(FilePanel* sender, const QString& path)
{
    bool allow = path != AddressBarModel::computerPath();

    if (sender == ui.local_panel)
    {
        ui.remote_panel->setTransferAllowed(allow);
    }
    else
    {
        Q_ASSERT(sender == ui.remote_panel);
        ui.local_panel->setTransferAllowed(allow);

    }
}

} // namespace aspia
<commit_msg>- Correct closing of the dialog when the connection is disconnected.<commit_after>//
// Aspia Project
// Copyright (C) 2018 Dmitry Chapyshev <dmitry@aspia.ru>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#include "client/ui/file_manager_window.h"

#include <QDebug>

#include "client/ui/address_bar_model.h"
#include "client/ui/file_remove_dialog.h"
#include "client/ui/file_transfer_dialog.h"
#include "client/ui/file_manager_settings.h"
#include "client/ui/file_mime_data.h"

namespace aspia {

FileManagerWindow::FileManagerWindow(ConnectData* connect_data, QWidget* parent)
    : QWidget(parent)
{
    ui.setupUi(this);

    QString computer_name;
    if (!connect_data->computerName().isEmpty())
        computer_name = connect_data->computerName();
    else
        computer_name = connect_data->address();

    setWindowTitle(tr("%1 - Aspia File Transfer").arg(computer_name));

    FileManagerSettings settings;
    restoreGeometry(settings.windowGeometry());

    ui.splitter->restoreState(settings.splitterState());

    QString mime_type = FileMimeData::createMimeType();

    ui.local_panel->setPanelName(tr("Local Computer"));
    ui.local_panel->setMimeType(mime_type);
    ui.local_panel->setDriveListState(settings.localDriveListState());
    ui.local_panel->setFileListState(settings.localFileListState());

    ui.remote_panel->setPanelName(tr("Remote Computer"));
    ui.remote_panel->setMimeType(mime_type);
    ui.remote_panel->setDriveListState(settings.remoteDriveListState());
    ui.remote_panel->setFileListState(settings.remoteFileListState());

    connect(ui.local_panel, &FilePanel::removeItems, this, &FileManagerWindow::removeItems);
    connect(ui.remote_panel, &FilePanel::removeItems, this, &FileManagerWindow::removeItems);
    connect(ui.local_panel, &FilePanel::sendItems, this, &FileManagerWindow::sendItems);
    connect(ui.remote_panel, &FilePanel::sendItems, this, &FileManagerWindow::sendItems);
    connect(ui.local_panel, &FilePanel::receiveItems, this, &FileManagerWindow::receiveItems);
    connect(ui.remote_panel, &FilePanel::receiveItems, this, &FileManagerWindow::receiveItems);
    connect(ui.local_panel, &FilePanel::newRequest, this, &FileManagerWindow::localRequest);
    connect(ui.remote_panel, &FilePanel::newRequest, this, &FileManagerWindow::remoteRequest);
    connect(ui.local_panel, &FilePanel::pathChanged, this, &FileManagerWindow::onPathChanged);
    connect(ui.remote_panel, &FilePanel::pathChanged, this, &FileManagerWindow::onPathChanged);
}

void FileManagerWindow::refresh()
{
    ui.local_panel->refresh();
    ui.remote_panel->refresh();
}

void FileManagerWindow::closeEvent(QCloseEvent* event)
{
    FileManagerSettings settings;

    settings.setWindowGeometry(saveGeometry());
    settings.setSplitterState(ui.splitter->saveState());

    ui.local_panel->updateState();
    settings.setLocalDriveListState(ui.local_panel->driveListState());
    settings.setLocalFileListState(ui.local_panel->fileListState());

    ui.remote_panel->updateState();
    settings.setRemoteDriveListState(ui.remote_panel->driveListState());
    settings.setRemoteFileListState(ui.remote_panel->fileListState());

    emit windowClose();
    QWidget::closeEvent(event);
}

void FileManagerWindow::removeItems(FilePanel* sender, const QList<FileRemover::Item>& items)
{
    FileRemoveDialog* progress_dialog = new FileRemoveDialog(this);
    FileRemover* remover = new FileRemover(progress_dialog);

    if (sender == ui.local_panel)
    {
        connect(remover, &FileRemover::newRequest, this, &FileManagerWindow::localRequest);
    }
    else
    {
        Q_ASSERT(sender == ui.remote_panel);
        connect(remover, &FileRemover::newRequest, this, &FileManagerWindow::remoteRequest);
    }

    connect(remover, &FileRemover::started, progress_dialog, &FileRemoveDialog::open);
    connect(remover, &FileRemover::finished, progress_dialog, &FileRemoveDialog::close);
    connect(remover, &FileRemover::finished, sender, &FilePanel::refresh);

    connect(remover, &FileRemover::progressChanged,
            progress_dialog, &FileRemoveDialog::setProgress);

    connect(remover, &FileRemover::error, progress_dialog, &FileRemoveDialog::showError);

    connect(progress_dialog, &FileRemoveDialog::finished,
            progress_dialog, &FileRemoveDialog::deleteLater);

    connect(this, &FileManagerWindow::windowClose, progress_dialog, &FileRemoveDialog::close);

    remover->start(sender->currentPath(), items);
}

void FileManagerWindow::sendItems(FilePanel* sender, const QList<FileTransfer::Item>& items)
{
    if (sender == ui.local_panel)
    {
        transferItems(FileTransfer::Uploader,
                      ui.local_panel->currentPath(),
                      ui.remote_panel->currentPath(),
                      items);
    }
    else
    {
        Q_ASSERT(sender == ui.remote_panel);

        transferItems(FileTransfer::Downloader,
                      ui.remote_panel->currentPath(),
                      ui.local_panel->currentPath(),
                      items);
    }
}

void FileManagerWindow::receiveItems(FilePanel* sender,
                                     const QString& target_folder,
                                     const QList<FileTransfer::Item>& items)
{
    if (sender == ui.local_panel)
    {
        transferItems(FileTransfer::Downloader,
                      ui.remote_panel->currentPath(),
                      target_folder,
                      items);
    }
    else
    {
        Q_ASSERT(sender == ui.remote_panel);

        transferItems(FileTransfer::Uploader,
                      ui.local_panel->currentPath(),
                      target_folder,
                      items);
    }
}

void FileManagerWindow::transferItems(FileTransfer::Type type,
                                      const QString& source_path,
                                      const QString& target_path,
                                      const QList<FileTransfer::Item>& items)
{
    FileTransferDialog* dialog = new FileTransferDialog(this);
    FileTransfer* transfer = new FileTransfer(type, dialog);

    if (type == FileTransfer::Uploader)
    {
        connect(transfer, &FileTransfer::finished, ui.remote_panel, &FilePanel::refresh);
    }
    else
    {
        Q_ASSERT(type == FileTransfer::Downloader);
        connect(transfer, &FileTransfer::finished, ui.local_panel, &FilePanel::refresh);
    }

    connect(transfer, &FileTransfer::started, dialog, &FileTransferDialog::open);
    connect(transfer, &FileTransfer::finished, dialog, &FileTransferDialog::onTransferFinished);

    connect(transfer, &FileTransfer::currentItemChanged, dialog, &FileTransferDialog::setCurrentItem);
    connect(transfer, &FileTransfer::progressChanged, dialog, &FileTransferDialog::setProgress);

    connect(transfer, &FileTransfer::error, dialog, &FileTransferDialog::showError);
    connect(transfer, &FileTransfer::localRequest, this, &FileManagerWindow::localRequest);
    connect(transfer, &FileTransfer::remoteRequest, this, &FileManagerWindow::remoteRequest);

    connect(dialog, &FileTransferDialog::transferCanceled, transfer, &FileTransfer::stop);
    connect(dialog, &FileTransferDialog::finished, dialog, &FileTransferDialog::deleteLater);

    connect(this, &FileManagerWindow::windowClose, dialog, &FileTransferDialog::onTransferFinished);

    transfer->start(source_path, target_path, items);
}

void FileManagerWindow::onPathChanged(FilePanel* sender, const QString& path)
{
    bool allow = path != AddressBarModel::computerPath();

    if (sender == ui.local_panel)
    {
        ui.remote_panel->setTransferAllowed(allow);
    }
    else
    {
        Q_ASSERT(sender == ui.remote_panel);
        ui.local_panel->setTransferAllowed(allow);

    }
}

} // namespace aspia
<|endoftext|>